RubyConf 2015

Casos de uso reales para las matrices en aplicaciones Ruby

Micah Adams  · 

Transcripción

Extracto de la transcripción automática del vídeo realizada por YouTube.

- Hey, good morning everybody. I know it's a little informal, I don't know if somebody was supposed to introduce me, but it's 10:41 and I like to be punctual, so let's go. I'm really excited to be here, it's my first time at Ruby Conf, first time speaking

here too, so it should be pretty cool, plus I've been listening to hip hop all morning to get pumped up for this talk, so. So, my name is Micah Adams, I work for Mode Set, it's a software consultancy based out of Denver and we focus on early stage startups.

So, we do development for them and our goal is usually to get our startups from series A to series B funding. Most recently we worked with Ello, which is a social network that's ad free, if anybody's on that. So, pretty cool. So, the title of my talk is "Not

so Neo in the Matrix" and of course, you're probably wondering, "why matrices?" There's probably two or three groups in this talk right now, some of you probably use matrices like all the time and you're awesome at it, so I ask you to be kind to me during

the Q and A session, and don't grill me too hard and put my feet to the fire too hard. Others of you might not use matrices at all, maybe you're kind of newer to programming, maybe you don't have such a formal background in programming, things like that. And

then some of you might fall into the third camp which is very much like myself, where actually matrices became like this new revelation because I had just forgotten about how much I'm using them in my code. So, for me, this reintroduction happened during kind

of a short foray into OpenGL programming on Android. So, I had a client who wanted us to develop a virtual reality application using the cardboard headset in the SDK that Google came out with, and I did that, it was a really, really quick project, it was only

a couple weeks long, we just slammed down some code for that. But I was getting all Baader-Meinhof and I started seeing matrices everywhere. I started seeing matrices in my sleep, I started seeing it down the street when I was walking, I started seeing it

in old code when I reviewed like old code that I had contributed to, I started seeing matrices then, and it became a little bit of an obsession to me and I also realized like, you know, how much I use it versus how much I'm aware of when I use it. So, I formulated,

you know, kind of a hypothesis and the hypothesis is kind of not that mind bending, it's pretty straightforward. That matrices are useful in all sorts of situations and not just in the OpenGL application I was working on, right? Matrices are used everywhere

for all kinds of things and all kinds of different domains. So, I really wanted to explore that hypothesis with this talk. So, what I found out was I had forgotten how prevalent that data structure is. I use matrices constantly, but without really stopping

to consider why I'm using that data structure and I deeply repressed all memories of calculating the inverse of a three by three matrix by hand, I need therapy for that stuff. Has anybody done that? Any math majors or any? Yeah, so brutal, like the amount

of calculations you have to do, you just thank your lucky stars that computers exist to do this for us, right? The other thing I found out is that Dungeons and Dragons is a great domain for me to explore new domain patterns. I am a ultra mega Dungeons and

Dragons nerd, I've been playing since I was like seven years old, I own every edition of the game, I, you know, I've considered getting Gary Gygax tattoo, I mean, it's really part of my life and I'm a domain expert in Dungeons and Dragons, so when you're trying

to explore new programming concepts, using your domain expertise is a great way to flash out those ideas, right? So, we're gonna talk a lot about Dungeons and Dragons in this and I have a little interlude, yeah, I have a little interlude for people here who

might not be into Dungeons and Dragons, but, you know, we'll figure it out. So, what I hope you as the audience get from experiencing this talk is a renewed interest in matrices, awareness of when you're using them in your code, but not only awareness, but

when you should be just removing it, right? Cause as we're gonna see in one of the code examples I have, a matrix in that example is really just brute forcing code and there's times when it's not appropriate, and there's times where it is appropriate. And

when you get like me, you get obsessed with a concept, sometimes you try and insert it everywhere, you get too excited about it and put it in places it doesn't belong. So, with that the caveat is, your mileage is gonna vary with some of the code examples here.

Okay, so the aim of the talk is not to tell you how to use matrices, but it's to make you more aware of matrices and how they might be used. But if you don't need it, like I said before, if you don't need it, please, please, please leave it out because there

are certain times where it's just not very performant. So, the "too long, didn't read" talk, so if somebody needs coffee and they're like really not interested in this, you can watch this slide and you can leave, and I won't be hurt, okay? Too long, didn't

read. Matrices are pretty much just multidimensional arrays, vectors are pretty much just arrays. I just blew your mind right now. So, those are interesting factoids, right? But the context around them is what kind of flushes out this talk. So we're gonna

explore the context of that to a greater degree. So, to get more context on those, we're gonna talk about fields, some of the mathematical concepts around fields, we'll talk about vectors and matrices, and then we're gonna go through our three code examples,

kinda flush that stuff out. So, what the heck is a matric anyway? Well simply put, it's a array of elements that have been organized into rows and columns. Very simple stuff. We can think of a matrix as being composed of vectors, right? So, a column that is

in a matrix is a vector, a row in a matrix is a vector. The elements of a matrix can be considered as being over, what we call, over a field. So, that begs the question of when do you actually, when should you use a matrix? The snarky, grumpy developer in

me wants to say, "well, it depends". But one way to actually figure that out, is when it's appropriate, is to look at some places where matrices, and vectors, and mathematics around them are actually being used in programming, right? So, the first thing that

everybody thinks about when they think of a matrix or matrix manipulation, is in the context of graphics or graphical programming, right? And this literally is just in some way, shape, or form using mathematical primitives, polygons, and then manipulating

them. So, I don't wanna get too much into three-dimensional programming because it's way out of the scope of this talk, so let's talk a little bit about how vectors and vector manipulation can be used on two-dimensional shapes, as a quick and easy introduction

to this stuff. So, what we see here is a little animation of a triangle and it's being scaled, right? And it's kind of like throbbing, scaling over time, it's on a timer, right? How is this actually being achieved? Well, we have some interesting parts of the

[ ... ]

Nota: se han omitido las otras 3.538 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.