Coding 101 34 (Transcript)
Shannon Morse: Today on Coding 101 we are getting
classy with practical classes. Are you ready? I know I am.
Netcasts you love from people you trust. This is Twit! Bandwidth
for Coding 101 is provided by CacheFly. At cachefly.com
Shannon: This episode of Coding 101 is brought
to you by Lynda.com, linda.com is an easy and
affordable way to help you learn. Instantly stream thousands of courses created
by experts on business, software, web developing, graphic design and more. For
a free trail visit Lynda.com/c101. That’s Lynda.com/c101. And
by Squarespace, the all in one platform that makes it fast and easy to create
your own professional website or online portfolio. For a free 2 week
trial and 10% off, go to squarespace.com and use the offer code CODING.
Father Robert Ballecer: Welcome to
Coding 101, it’s the place where we let you in on the secrets of the coding
masters. I’m Father Robert Ballecer.
Shannon: And I’m Shannon Morse. And for the next
30 minutes we’re going to get you all learn-ded up on everything you need to
know to be a code warrior.
Fr. Robert: Absolutely. Now Shannon, we’ve been
kind of stalled on classes because it’s actually-
Shannon: Because they’re weird.
Fr. Robert: Because they’re weird. We’ve had a lot
of people who have said- rightfully so- I still don’t get how this is useful.
They understand how classes work, they understand how abstract classes work.
They understand how interfaces work, but it’s kind of tricky to write something
where you’re thinking, this is just extra work
Shannon: Yes, you know, my biggest problem with classes so far- I understand how to make them, I
understand how to build them and how to make it implemented, but my problem is
when am I going to use a class as opposed to just putting it all on one program
style sheet.
Fr. Robert: Right. Which is today what we’re going
to do is we’re going to give you some practical examples, and all of these
examples we give you today will be available on the show notes page. Now we
haven’t been putting it into the GitHub because we’re actually building
packages. It’s not just one file anymore. And what we found was, if we made
multiple files, people were complaining that it’s too difficult for them to put
it in the proper place. So I’m actually zipping up all the program examples, there’s
a link in the show notes page that you can download them from, and then when
you open up the project file, it will open up exactly as it is on our
computers.
Shannon: Oh that’s awesome. I didn’t know you
could do that with GitHub. Yay. Well, I’m ready, are
you ready to do a little bit of Snub’s compiling.
Fr. Robert: You know, I’d
like some compiling please.
Shannon: Alright, I’ll make it short today. I’ll
make it very, very short so let’s go ahead and jump over to my computer where I
have visual studio express 2013 opened. Now my example is not super, super
practical, but hey, it works for me. And that’s what matters. So first off I
have just program.cs which is what you normally open up with. I’ve named it
episode 34 snubs example, and the class is just called program. So I left that as
the default. The first line is a default. And then down here you see a whole
bunch of different commands. So what are all of these? Well, I have a whole
bunch of new names for my class, my class called anime. So you’ll see the same
thing over and over and I’ve done it a couple of different times. First off, I
made this first amine class and I named it anime 1. And then it’s going to
write anime 1, which is name of anime. Now down here, I have anime 1 and I set
anime as sailor moon. So when it types out, it should type out as sailor moon.
Same thing as this one, it should type out as dbz, but what do these do? Weird huh? And down here we just have press enter to exit.
Now if you go up to my class, and I named this one class1.cs, this one is
called public class anime. So that’s where we see that name again. Down here, I’m
going to have- let me erase that because that’s not correct anymore, because I
messed with it a little bit. So down here I have the name of anime, which is where
you’re going to put in whatever the name of the anime is that you decided to
call it. If you do not have a name, it just comes up as nane, which means what,
in Japanese. And then here I have a conjugation, I think it’s called. And under
that I have set anime where you can actually add a name of the anime. So this
is where this comes into play. Now if I go ahead and build this file, so ill
build a solution and hit start. You’ll see that it says nane for the first one,
sailor moon, dbz, and nane, nane, nane, press enter to exit. So press enter to
exit. Interesting isn’t it? Hmm.
Fr. Robert: Nice, I like that. Okay.
Shannon.
Yeah. So it’s not very practical, but you could use this to- say you work at
funimation or something. You could end up listing out all the different animes
for your website into this c sharp code to put on your site or something like
that.
Fr. Robert: Yeah, one of the ways I see you using this, and we’ve been trying to stress this- in fact, we’ve
been hitting you over the head with this, I know this. Is to
enforce a hierarchy. Once you have a set number of methods and variables
and procedures that you want to attach to any anime series, you would build
that anime class.
Shannon: Yeah, exactly. So that’s what I was
doing in this one. Of course if I wanted to take the time to do it, I could
also add new classes to this, such as an episode listing for a specific anime.
And then if I wanted it to not coincide with all animes for all classes, I
could always over ride that so it just coincides with a certain anime that I’ve
figured out. Same with like a list of characters or a list of the voice actors
or something like that. So many ways that you can use it and you can also use
it with- after users have put information in themselves.
Fr. Robert: This is something that we’re going to
make available for all of our listeners, all of our viewers, you’ll be able to
download this code so you can play with it, and yes, I know, I know that on the
surface it looks like this is a waste of time, you should just all include in
one big program. And I know that I’ve told you this-
Shannon: It’s not, it’s so much more work.
Fr. Robert: It really is so much more work. And
you’re going to- this is the way that you should program. This is the way that
you should organize your code. And that’s what we’re trying to really push on
you. And I’m sorry if it feels as if we’re covering the same thing over and over
again, but this is really important.
Shannon: I’m going to engrain it into your head.
I also have a viewer example. Well, not really a normal viewer example that we
share where I show you the example code and everything. But you might remember
that Nathan Flummer over in our Google+ community had recently asked us hey, I
want you to mess with this Fibonacci sequence and answer this question that I
ask of you. I don’t think anybody actually did it in the Google+ community. I
tried it myself and I kept on getting errors. But he did put the answer in
here. So if you want to try his code, and see if you can get it yourself, go
over to our Google+ community, which is bit.ly/twitcoding101 and you can check
out his answer. So try out that code and see if you can figure out his problem
solving.
Fr. Robert: Right. And remember we’re just trying
to give you ways to get into it. And one of the best ways to get into it is to
try to solve a problem. Because if you’re solving a problem
rather than coming up with code, it’s a much better way to think about
programming. We stress this again, since the first module, which is, the
code is inconsequential. The thought processes that go into breaking down a
problem into solvable chunks is really what we’re
after.
Shannon: Alright, I’m ready.
Fr. Robert: I think this is a good time for us to
take a pause. And maybe fill the knowledge hole. I talk about the knowledge
hole in my other program- are you okay?
Shannon: Nom, nom, nom, nom, knowledge hole?
Fr. Robert: It’s this part of our minds that once
we start into a topic we want more. You’ve done this right?
Shannon: Oh yeah, all the time.
Fr. Robert: Those late nights where you just start
click, click, click, click. And that’s because we’re naturally curious. So a
program like this, like coding 101, even though we’ll give you the basics, even
though we’ll give you the introduction, sometimes you need to go someplace else
to get something more in depth. Which is why I’m happy that
Lynda.com is a supporter of coding 101. Now what is Lynda.com? Lynda.com
is the true source of knowledge online. If you want to learn about business,
you want to learn about programming, if you want to learn about video editing,
you can find it on Lynda.com. Lynda.com is an easy and affordable way to help
you learn the way that you want to learn. You can stream thousands of courses
created by experts on software, web development, graphic design, and more. In
other words, it’s your life. Taught to you the way you want it to be taught to
you, online. How can it get better than that. Lynda.com works directly with industry experts and software companies to
provide timely training, often the same day that new versions are released. So
you’re always up to date. Your skills will always be ready to go. All courses
are produced at the highest quality which means that they’re not going to be
like those low quality YouTube videos. I’m not saying all YouTube videos are
low quality, I came from YouTube. You came from YouTube Snubs. But sometimes
you want to concentrate on the material than on the fact that so and so is using a bad mic. Or so and so has really bad lighting.
That’s what Lynda does. They give you the way to learn that has the fewest
distractions. Lynda also includes tools like searchable transcripts or
playlists and certificates of course completion so you can look for and find
exactly what you need at that time. And so that you can tell the world by
publishing your certificates on LinkedIn, what you’ve drained in. it’s a great
way to show potential employers what you’re ready to tackle. Now whether you’re
a beginner or advanced, Lynda has courses for your experience level. You can
learn while you’re on the go with Lynda.com apps for the iPhone, iPad and
Android. Or you can watch on your Mac, you’re PC, your desktop or your laptop.
They have one low monthly price of $25 which will give you unlimited access to
over 100,000 video tutorials. Just think about that. 100,000. What could you do
with 100,000 instructional video tutorials? Well, you could pretty much learn
anything you want to learn. Now premium members with an annual plan can
download courses to their iPhone, iPad, Androids, and watch them offline. Which is great if you want a repository that goes with you. Anytime you need reference, Lynda.com will be there for you. Now I have been
using Lynda.com for programming in aid of course with Coding 101. It’s always
good to get a refresher on things that we’re going to be talking about. So for
example, if I want to start developing for Android and I could jump into this,
ask DK tutorial that will show me step
by step what I need to do in order to create an Android app. it’s that simple
folks. You want to learn, Lynda wants to help you learn. Now for any software
you rely on, Lynda.com can help you stay current with all software updates and
learn the ins and outs of being more efficient and productive. I love Lynda and
I know you will too. And we’ve got a special offer for you to access all of
their courses free for 7 days. Visit Lynda.com/c101 to try Lynda.com free for 7
days. That’s Lynda.com/c101 and we thank Lynda for their support of coding 101.
How about a little bit of Ivory Tower?
Shannon: I’m ready.
Fr. Robert: Alright, now I wanted to start this off
a little bit different because we’re going to be doing a classic classes smack down. With something that really is very Ivory
Tower. This is sort of pie in the sky, something that’s not all that practical
at the moment but is very cool and is something that maybe a prospective
programmer might be wanting to get into. And that is bit coin might save the
world.
Shannon: What?
Fr. Robert: Okay, not save the world, but it could
change the face of programming. What we have is we have a young man, a college
dropout. How many stories start with that, right? The college
dropout who made good. In fact, if you go to my computer, Josh, what you
see is you see that this young man, Vitalik Buterin, he started up a new
project that he’s calling project Ethereum. And what it is, it’s an effort to
use the technology behind bitcoin to change the way that we program and publish
programs on the internet. Now you may be asking, but bitcoin is – how do I use
bitcoin to change the world? Quite simply, it’s based on the block chain. You
understand how crypto currencies work right?
Shannon: Yes. Kind of.
Fr. Robert: So the block chain was absolutely
essential to any crypto currency. So bitcoin, licoin, dogecoin,
any of the other coins. The idea is you decentralize the control of the
currency. And the way that you decentralize it is you put it into a block chain.
Which means that the control over the tracking the finances and the ledgers and
who has done what and who has transferred money to whom, is controlled by all
computers rather than a central computer. Which makes it
impossible to shut down. Or at least very, very
difficult. It also makes it very
difficult to cheat. And how do you mess with the ledger when the ledger is
stored over thousands or millions of computers. Right. It helps to think of it as a massively parallel, massively redundant, ridiculously
backed up cloud server. Except that there’s not one single entity that’s
controlling it. So what he wants to do with project Ethereum is, they want to
be able to take that power, and apply it not just to a ledger, but any program
that you might write for use on the internet. Imagine this, so if there’s not
central authority for bitcoin, licoin or dogecoin, and if you take that same
block chain and you use it for, say hosting the next email service, or whatever
that you want to do, it means that you don’t have to worry about someone taking
down your email server, you don’t have to worry about it not being available as
long as there are participating nodes that are working on that block chain.
Your service will always remain up.
Shannon: Oh wow, that’s actually kind of cool.
Fr. Robert: Yeah. Now here’s the cool part. So Vatalik
had a campaign, a crowdfunding campaign, and he raised about 30,000 bitcoins,
which in today’s market, I think that’s about 15 million dollars USD. But he’s
using that to seed what is a crypto currency that he’s calling ethers. He’s
calling them ethers. And the idea is that it’s like a bitcoin and it’s like a
licoin or a dogecoin, but here’s the main difference, and this is something
that we’ve lamented. When you talk about a bitcoin, you’re talking about
mining. Usually mining, unless you’re buying it. Going
through an algorithmic cache until you find a proof and then you present that
proof to the block chain and the block chain will reward you with a certain
number of bitcoins right. But all of those calculations are wasted. You’ve got
computers priming all the time making these calculations and then if you get or
if you don’t get rewarded, that’s worthless calculations. You just wasted all
that processing power. He wants to create a block chain where all the
participating nodes are helping to host the software that’s in the block chain.
Now, you get money, as long as you’re hosting. Participating
in that block chain. And the people who host their software in the block
chain pay ethers in order to host their software. So it’s like mining but now
there’s actually some sort of service being provided. You’re not wasting the
processing power. We’ve talked about this a bit in the past on Know How, my
other show here on Thursdays and I think we’ve come to a time where we don’t
like the idea of just wasting electricity and processing power for nothing. And
if I could get rewarded by donating some of my computing time to, say, someone
who wants to host some supercomputing math blah blah blah, then I’m willing to
do that. If I get a little bit of something, something. So it’s not mining, it’s hosting. You’re now hosting. But it still uses a block
chain.
Shannon: That’s very interesting. It’s very
intriguing.
Fr. Robert: It’s intriguing and I honestly think
this is where we’re heading.
Shannon: This is the time. yeah. Its 2014.
Fr. Robert: Its 2014 and the idea of having
monolific servers in a back room somewhere that control everything, that could
be hacked, it’s kind of old school.
Shannon: It’s kind of old school, yeah. That’s
like 1990’s now.
Fr. Robert: We like to distribute it. Out into the cloud. Alright, let’s get away from that and let’s
talk a little something, something about classes. Now we promised you some
solid practical examples of how we use classes and we’re going to deliver.
Josh, if you could go ahead and go back over to my computer, this right here is
an example of a piece of code that Lou Well put together over the weekend. I
was playing with the ability of C Sharp to download things off the internet
using get, so you basically it’s a web call right. So there’s a file on the
internet that I want to get, which you’re going to want. This is how you do. And
how do I use C Sharp to get it, to bring it in? Now, check this out. If you
take away the comments, this is what my program actually looks like. That thing. That entire thing is my program.
Shannon: Wow, it’s not that long at all.
Fr. Robert: And half of it are comments. Which is what we want right, because we want people
to comment the code so we can understand what its doing. All this is doing, if you look at this, in the use statements, it
has something that we haven’t seen before. Using twit.tvcoding101.data.asynchronisdownloads.
Shannon: What?
Fr. Robert: This was a set of classes that Lou
created for me that allows me- see if you go over here Josh, if you could zoom
in on this- these are the individual classes that he has created. When I put
that in my using statement section, it means okay, make these available for the
program. Now, go ahead and back back out, I want to show what one of these
looks like. So let me go to the resumeable downloads. This is a class. This
defines a public class. Called resumeable downloads. And then these are all the
methods that go into that class. And essentially this is the back end code that
allows the program to access the network part of the computer.
Shannon: And I’m noticing this is not abstract so
you have to have all the complete code in there.
Fr. Robert: Right, so all the complete code, this
is a complete code. Right. But unlike say, putting
this into my main program, there’s a lot of members in
here that I’m probably not going to use. If I’m only using the download method,
then I don’t have to use the upload method. Or maybe it means I don’t have to
use the check some method. But that could all be in the class, I just pick and
choose what I’m going to use.
Shannon: You don’t have to use every single one.
Fr. Robert: I don’t have to use every single one.
But it’s nice to know that it’s there. It means that in future programs, if I
use this class, I can. Right. And then I’m also
including something here like the download state. So this is another public
class called download state, and as you can see there are no abstracts in here.
So this is a real class, this is ready to be instantiated. And this allows me
to check what the download state is so that I can be ready to download. Now let’s
go back to my program and Josh, I’m going to zoom in really quickly here. As
you can see, the first thing that this is going to do, and we’ve seen this
before, it’s going to instantiate a new object. And this object is going to be
based off of resume downloads which we took a look at over here. So this is a
class that was included with my using statements. It’s not in this program. I
have it nowhere in this program, but this allows me to make a new object based
on the class called resumeable downloads which I included in this synchronous
downloads package. Look how neat this becomes. Now it becomes, I create the
object, I create this string, which allows me to input okay, where’s the file
located and what is it called, and then I also tell it where’s it going to go.
I want it to go to my computer and I want it to go to a specific directory. And
then the rest of this is just using the download state class to download the
file according to the variables that I’ve set. Now when I run this, what it
will do is it will automatically go to podtrac.com which is one of our content
distributers, and it will start a console that will start downloading the files
to my computer. Now I can specify as many files here as I want, so this, folks,
this is the start of creating your own podcast catcher. So if you’re tired of
really bad RSS feeds, or really bad podcast catchers, what Lu has just done for
you, is he’s given you the basis, the class that you need to create your own.
You don’t have to code it. All you have to do is look at the comments in this
class to figure out what does what and then you’re good to go.
Shannon: That’s brilliant. I love it.
Fr. Robert: So we’re going to make this available,
this will be as is file, all in one. So if you download this project and you
run it, it will automatically start downloading one of our episodes, and then
you can go through there and say, you know what, I want to download something
from Hack 5. I want to download something from Revision 3.
Shannon: You just change the link.
Fr. Robert: You can change the link, you can create
a menu system, because we already know how to do that, and you can play with
the other methods that are included in the class that we didn’t use in this
particular program.
Shannon: That’s amazing. I love it.
Fr. Robert: I think when you start seeing stuff
like this, this is when classes begin- oh, that’s why you do that.
Shannon: It makes sense. That’s why you would
plug it in.
Fr. Robert: So what we’d like you to do is go ahead
and download this, try it. Makes sure it works. Because it
will work the very first time. And then play around. And I promise you,
once you realize how easy it is to use classes like this to interface with the interwebs, you’ll be hooked.
Shannon: Ooh, so fun.
Fr. Robert: We’re going to be getting over to our
code warrior Lou, who did assemble this for me, but I was messing around with
it for the longest time and I just couldn’t make the asynchronous downloads work.
And Lou is like “oh, yeah, I have a class here for you” boom.
Shannon: Oh, let me just fix that for you.
Fr. Robert: Let me, oh yeah, let me just take care
of that.
Shannon: Just give me like two minutes, I got
this.
Fr. Robert: That’s why he’s the code warrior. But
before we get there, you know what I’d like? I’d like a place where if I have
projects like this, I could make them available for people. I’m tired of
dealing with domains, I’m tired of registering blah,
blah, blah.
Shannon: I want my own .com, I want to be able
to upload as many photos as I want, I want to be able to embed a map, I want it
to look clean and crisp and very easy to understand and Squarespace did that
for me. And it was so easy and it was inexpensive too. So Squarespace.com, they’re
the all in one platform that makes it super, super easy to create your own
professional website or your online portfolio or your wedding website. They are
so great. Some of the reasons why of course you’re going to love Squarespace
just as much as I do, they’re constantly improving their platform with new
features, they have new designs that you can just use for your own. And they
have even better support. For example, you can get support from them 24/7,
every single week, even on holidays. If you want help they have a live chat.
They have email support plus they have a completely redesigned customer help
site as well. And they have beautiful designs. There are plenty to choose from
on there. They have over 25 beautiful templates for you to quickly build your
own personal or business site. And they have a great mobile experience.
Squarespace has developed templates with responsive designs which means that your site is automatically restructured to look
great on any device, no matter whether you’re using a smartphone, the new
iPhone, what is it, the 6+? Or just your computer, you’re desktop at home. It’s
going to look great on any of those and hosting is included. You don’t have to
go anywhere else to get hosting. They have it. They take care of the hosting
with a distributed network that does not go down. Even if
their server room is flooding. Seriously, it did happen, and my website
stayed up. Its inexpensive, it starts with $8 a month, and they include a free
domain name if you sign up for a year. So it’s perfect for my wedding website.
I had my own .com, I had my own domain name. It was
only$8 a month. And their code is gorgeous. Squarespace takes just as much
pride in their back end as they do with their front end design. So not only do
you have these gorgeous designs, but you also have really, really easy to code.
Squarespace even has a developer platform. So if you’re a coder for example,
you can get all up under there and be able to fix anything that you want. Just
to your liking. So if you really want to dig into site customization and
developer accounts, they never expire while in development. So you can take as
much time as you need before launching your site, and you don’t pay anything
until you actually go live on your site. On the internets. You have complete control on their developer platform, so you can edit all of
the code that affects the display of your website. Every
little line of HTML, every little bit of CSS and the JavaScript all under your
control. And they have git NSFTP support. There’s a git repository. They
have version control that comes standard. And you can connect to template files
via git or SFTP as well. And a little bit more in developer tools, there’s less
preprocessing, jasontemplating, script comboing, retina ready responsive image
handling, ha ha. And even more. So start a free 2 week trial with no credit
card required. And start building a website. See if you guys like it because it’s
gorgeous. When you actually decide to sign up for Squarespace, make sure to use
the offer code CODING. And get 10% off and show your support of coding 101. And
of course we thank Squarespace for their support of coding 101. Because a better web awaits and it starts with your new Squarespace
website. It’s gorgeous.
Fr. Robert: Yes, absolutely gorgeous. And speaking
of gorgeous, I think that definitely qualifies for the coding warrior who we’re
bringing in now. Are you ready? Ladies and gentlemen, Mr. Lou
Maresca from Microsoft. He’s our code warrior. He’s the man of the hour.
He’s the man who gave me this awesome, awesome software that I can now
customize ….
Shannon: I’m pretty excited about that.
Lou Maresca: Yeah,
hopefully people can get use out of it.
Fr. Robert: You know, it’s this sort of stuff, this
sort of program that we’re going to be giving to the audience,
that really gets them to finally, I think, make that transition to this
is a better way to program. I understand what they’ve been doing, we’ve had a lot of mail INS and a lot of comments from people, saying I don’t
understand why we’re learning this. This doesn’t make any sense. When they see
this, and when they see, oh, you mean I can use code that someone else wrote
and I don’t have to figure out how it works and I – I think then yeah, it’ll
work. So thank you, thank you very much.
Lou: Yeah, no problem at all.
Fr. Robert: Now this was how we access the get
features on your computer. Which is how we pull stuff off of
the internet. Which is very useful, crazy useful. In fact, as I mentioned, this could be the start of your own podcast catcher,
but you’ve decided you want to give us a little something, something else…. So
what are we doing today?
Lou: What I decided to do is to make
something more useful for people who like to use social network, I built a
twitter app. and it’s probably one of the simplest apps. You’ll be surprised at
how easy it is to use. And I’m going to actually show you a library that I’m
using to kind of get it to work but it’s so simple and hopefully everybody will
be able to play with it and try it out for themselves. So the app itself, you
do have to go register an app, so you would go like to dav.twitter.com and then
sign in and create an app for yourself. But we can put instructions on how to
do that in the notes and then they can basically go and do that themselves. Because they have to have some secret codes in
their app for it to work.
Shannon: Yeah, you have to have a key, correct?
Lou: Yeah, that’s right. But other than
that, the code itself is really simple.
Fr. Robert: Right. But now let’s be clear here. You
didn’t have to write this from scratch. You needed to apply for a DAV account,
you needed to get your super-secret number so that your program knew how to
access the twitter API, but the bulk of the programming was just a class
available on line that you were able to use in your code.
Lou: That’s right. And so I think that a
couple episodes ago we did a social networks abstract class. And so I just
basically used that so I could show okay, well, we already did that code so I’m
going to use that against this other library that I found online. A really cool
library called link to twitter. And you can go to its GitHub or to its codeplex
online and find it and I can actually show where that’s at in the show notes
too. Yeah, I just basically just used that and then I used the class that I already
wrote to kind of interact with it and it makes it really easy.
Fr. Robert: Nice, okay show us. Bring us in there
and show us how this works.
Lou: Yeah, sure. So if you show my screen
real quick, this is the social network class that we wrote a while ago. And you
remember it was just an abstract class. Sometimes it has properties in here
which is things that describe the class. But sometimes it had methods that
don’t really do anything. It doesn’t really have any code in here at all. And
then I built a twitter version of that where I basically inherited it and now I
actually had to create a function for it. And you’ll notice in here, this is
the code that actually works with this library that’s linked to twitter library
that I found. And again, its only 3 lines, it allows me to tweet a message. Very, very simple. And then this is inside my social network
class. So anytime I want to call post a message, the message is a string and I
just go ahead and send it off there after I’ve already authenticated myself. Very simple. And then if I show the actual window here, this
is a very simple window. All I did was go to the tool box, general tools here,
and I drag and dropped a couple controls, a button and a text box on here. And
then I double clicked on the button and it took me in here to the code and said
okay, when you click the button what do you do? I want to create a twitter
object, and I want to log in and then I want to post a tweet. And really, really simple code, yeah.
Shannon: That’s awesome.
Fr. Robert: Wait, that’s the program?
Lou: That’s the program. That’s it.
Fr. Robert: How does that work Lou, I don’t
understand, that doesn’t have any code in it.
Lou: So honestly, it’s real simple. So if we
actually run this real quick, it’s going to first ask me log in, because you
have to log into twitter. And then this is the simplest way that you can- it’s
called PIN authentication on twitter, it’s just a way to authenticate the user.
And then you just click on authorize PIN. And again that all
comes for free. And then this simple app is this little text box, and I
can say on coding 101. And hit tweet. And that’s it. It’s already out there. And
if I pop out here to my twitter feed, and… yeah. There it is.
Fr. Robert: Wow, that’s crazy easy.
Lou: Yeah. So if we go real quickly back
through the code, I want to show you what we did here. So I basically just
created a really simple PBF app. once I created that…
Fr. Robert: By the way, if you don’t understand
what we’re doing with the WPF app, look at episode 7 and 8 from the first
module from C Sharp. You’ll see the step by steps.
Lou: Yep. And really all it does is add a
bunch of forms in here and it’s giving me a form designer. And like I said, all
I did was drag and drop a text box and a button on there. And that’s really
what the bulk of this code is, is those two things. And then again, I used a
social network class that we already used before, and again, it doesn’t really
have any code in it, it’s just a framework. It’s basically just the plans for
what I want to do right. The blueprints for what I want to do. I want to post,
I want to post with a photo, that kind of thing. And so if I actually wanted to
write code to post with a photo, again, it’s really easy for me to do that. I
basically could just copy this code and I could just use tweet- again there’s a
method called tweet with photo. I think its called
tweet with media. Yeah. So it’s real simple super. And I can put my message in
here. So I can do say hey, put the message that I passed in, and then is this
possibly sensitive? Nah, it’s not sensitive. And then what the image is. So I
can just put the photo that I send in here. And then that’s it. There you go.
Now I can actually post a photo to twitter. Real simple
stuff. Again, that’s what classes allows you to
do. is it allows you to abstract the complexity, take away the complexity from what’s
underneath the covers to do all of this, and make it really easy for you to
build the app without you having to do any craziness in your app to kind of
complicate things in your head and on the screen.
Shannon: I feel like any time you do this, it’s
a lot easier to share it with a team. Like, classes are perfect for teams.
Lou: Yep. And if you write the class well
enough, it will be completely broken apart and you can just package it up and
send it to somebody and say they just use this.
Fr. Robert: When you’re beginning, classes are
going to mainly be for you to take someone else’s code, as Lou was doing here
with the twitter API and the twitter class. And be able to use the methods that
they created to do the things that you want to do. as you get more advanced,
you’re going to find that your code, especially if you do it right, and as Lou
says, if you can decouple your class, from the program that’s using it, then
people will start using your classes. This is how the world of open source
works. People writing good code that other people want to use, getting hooks
into it. And I can’t stress enough that this is ultimately where you want to
end up. There’s no greater compliment in the world of programming than someone
else saying “I really like that class, can I get a copy”. Yes. No there, is.
There is one better compliment, which is we love your programming, we’d like to buy it for a billion dollars.
Lou: Hey, maybe a twitter app. maybe twitter.
Fr. Robert: Now Lou, can you actually show us the
class that you’re turning into an object here? It’s in your workspace right?
Lou: Yep. So the twitter guy, this is the
twitter class right here. It’s again, very simple, its only 3 lines. Because it gets to inherit from its parent here. But again,
it has a post method. Post for an image and then a log in image. Again, very
simple code in here to say hey, go use this link to twitter library to go and
authorize me and then show the log in box. And that’s what you saw, that little
ebox that says authorize or whatever.
Fr. Robert: People in the chat room are asking
about that, they’re asking “so where did that box come from?” well, its right here. Lou just showed you the method that’s
creating that.
Lou: That’s right. And it’s just another
window, but in the window itself, it actually spins up this PIN authorizer,
which is part of the link to twitter library. But it’s another class that’s
supported in there.
Fr. Robert: Now you could hard code all of that in
there. And that would be a horrible, horrible app. don’t ever do that.
Lou: You notice here I take my secret code
and my secret key that I get from my- so If I were to go over to my twitter
apps, if I were to sign in here and then create, its apps.twitter.com, if I
were to sign in and create an app, they would give me a secret code and a
secret key. And then I put it in a config file. So that’s why it’s kind of
hidden behind the scenes. And then you guys can put whatever code you want in
there. But again, don’t put it in your code.
Fr. Robert: You could. It would work. It actually
will work. The problem is anyone who gets ahold of your code now has you. You
are owned. Yeah so don’t do that. That’s bad. Lou, again, I’m hoping that this
time, people will see these examples, they’ll download this program, your
program, snub’s program and they’ll say “okay, this is worth it” and they’ll
start exploring. Especially with the twitter class, especially with this
download class. They’ll be able to fool around and put enough together that
they’ll finally decide that okay, this is how I will write my programs. Do you
have any advice that you want to give to them as they head on their classy way?
Lou: Yeah definitely. I saw a lot of posts
on google+ and on twitter, and it is kind of confusing because a lot of other
languages are like, oh we don’t support object orientation, when creating
objects in classes. And some of those languages are really easy. They’re what
you call interpreted languages. Or very easy to compile at one time, or do the
code at one time. But again, classes make it really easy for you- for me it’s
kind of like organization in my head too. So if I say oh I’ll give you
something that does that for you, it’s like, Padre, I’ll give you a resumeable
download- I’ll give you some class that will download stuff and use every
processor on your machine to do it. Like that sounds super complex and so I’m
going to give you classes that are really easy. You call downloads, you pass
the file name and then it’s going to be done. And to me that really makes it
easy for everybody to understand that classes allow you to kind of package up a
complexity and give it to other people.
Fr. Robert: Right. And there’s nothing like being
able to do that. To say, oh this is a super huge class, but you can create an
object and these are the two methods that you want to use and this is how you
use them. And that’s what we’re talking about. That’s really how simple you can
make it. Lou Maresca from Microsoft, we want to thank you again for being our
code warrior. It is always a pleasure to talk to you. It is always a pleasure
to see your code. And again, thank you for this, because I was struggling with
the whole down- I don’t know what I was doing. I think the problem was I was
trying to make it more complicated than it actually had to be.
Shannon: It’s usually what happens.
Lou: You can get way out of hand with code. I’ve
done that before. You get way out of hand sometimes.
Fr. Robert: Oh, by the way, I should mention, if
you’re going to use the download code, there’s an extra special bonus for the
advanced programmers. There is no exception handling and we haven’t made it customizable,
everything’s kind of hard coded in there. so if you’re feeling frisky, why not
drop it into a WFM, why not give it error checking, make sure that you’re not
going to run into any exceptions, and why not make it completely configurable
with some dialog boxes. That’s your challenge.
Lou: You kind of tricked me a little bit
because you said hey I need a class that does downloads. Asynchrosies. Okay. So I just did it really quick, I
didn’t think you were going to use that.
Fr. Robert: It was a lot of fun. We want to go bare bones, we don’t want to get too complicated. Lou
Maresca, if you could tell the folks where they can find you, where they can
find your work.
Lou: Definitely. @LouMM on twitter and about
me Lou MM. and of course all my works on
sierram.dynamics.com.
Fr. Robert: Fantastic. And we will see you next
week. What do you think we should venture into next Lou?
Lou: I don’t know. I think we’re getting
pretty close to maybe doing some more fancy stuff. Maybe moving into mobile or
tablet platforms. I don’t know. As long as people are okay
with the class thing by now.
Fr. Robert: Yeah. How about this. We’ll keep our ears out, make sure you go to the Google+ group and tell us, I’ve
got classes, or give me one more. We could give you one more, I’d like to move
on to something else, but I don’t want to do it until people have classes down
pat. Unless people are dedicated to writing their code in the
right hierarchy. Because honestly, if that’s all we get out of the
second module, I will be very, very happy. How about that Lou, does that sound
good?
Lou: Sounds great. Yeah let’s do it.
Fr. Robert: Ladies and gentlemen, Mr. Lou Maresca,
sr. software developer over at Microsoft, good friend of the TWiT TV network,
sir we salute you.
Lou: Yeah. Thank you, guys.
Fr. Robert: And folks, we salute you too. That’s
right, the geek, the gal, the man, the woman who watches our show every single
week, we wouldn’t have a show without them right?
Shannon: That’s so, so right. Thank you so much
for watching the show. And of course if you want to find all of our show notes
and all of the information available about coding 101, or you just want to subscribe because you found us randomly on YouTube or
something, go over to Twit.tv/code or twit.tv/c101, both of those links work.
And you can find everything, including the links to our GitHub as well.
Fr. Robert: Yeah. And our GitHub
and also the links to the individual software packages. We want to make
it easy. Because we’re listening to you. And people
were saying I don’t want to have to go to 12 different GitHubs to get all the
different codes for the different classes that will run this program. So we’re
going to package everything up. There’s going to be a nice easy zip for you to
download and get the projects that we worked on today. And don’t forget you can
also find us on iTunes. Download coding 101 on iTunes if you are an iPerson.
Especially if you’re getting a new iPhone 6 because I’ve heard that we look
damn good in 5.5 in.
Shannon: We’re also on YouTube, we’re on the Googles, all over the Googles. We’re on the YouTubes,
youtube.com/twitcoding101, and you can also find us on the Google+ community.
And I made a little bitly link for that. Its
bit.ly/twitcoding101. That’s where we have most of our community. That’s
where you can find all sorts of information and lots of really, really helpful answers
to any of your questions. People are very, very open to answering pretty much
anything over there.
Fr. Robert: It’s not a board it’s a community. Also
if you don’t like G+, we’re doing the twitter groove. And we’re probably going
to write our own custom apps, I want mine to tweet every time Jeff stands up. I’m
going to write something for that. You can also find us doing the twitter thing, I’m at twitter.com/padresj.
Shannon: And I am @snubs.
Fr. Robert: Yeah. Don’t forget we do this show live
every Thursday. 1:30pm pacific time, you’re going to find us at live.twit.tv
and as long as you’re watching us live, which is great by the way, because you
get to see pre show and post show and the bloopers that get- you get to watch
it live. You’re going to be able to do that. And you can drop in at irc.twit.tv
and be part of our chat room. You see us every once in a while looking down
here. That’s where the chat room lives. They get to talk to us during the show.
Sometimes we answer their questions, and we always pay attention. So irc.twit.tv. Until next time. I’m
Father Robert Ballecer.
Shannon: I’m Shannon Morse. End of line!