Programming Throwdown - Java
Episode Date: August 3, 2012This show covers Java, a semi-compiled language used heavily in web and mobile development. News: Ouya android gaming console, Is C/C++ Worth It?, Engineered Jellyfish. Tools of the BiWeek: C...ygwin, MinGW and Macports, uShare. ★ Support this podcast on Patreon ★
Transcript
Discussion (0)
Hosting provided by Host Tornado.
They offer website hosting packages, dedicated servers, and VPS solutions.
HostT.net.
Episode 17, Java.
Take it away, Patrick.
All right, mixing it up this week.
So having a young daughter
and talking to other people at work
with young kids we were having a discussion the other day
which I thought was interesting
about playing video games with your kids
so obviously my daughter is far too young
to play video games unfortunately
it would be a nice excuse to play even more
video games than normal
I saw a one year old playing anger birds the other day
were they doing it well? they were not they weren't doing too bad i mean like in other words
like the bird was moving you know they weren't getting a high score or anything but like you
know they could see that i think the one year old was starting to figure out that like you know if
they moved their finger a different way the bird did something different they're kind of starting
to get the whole like the bird doesn't go as far if you move your finger down or whatever oh wow they're doing
the i was impressed that's pretty good yeah i it's a hard it's a hard thing so um there's
different classes you can try to play like an educational style games like i remember growing
up you know you had these games which would teach you math you know you would run around the level
and try to hit the blocks like the cookie monster one where you had to like add
the cookies yeah and there's all these you know but those are kind of overtly
educational right like obviously this is you're learning you know and at the
expense of gameplay and then there's like trying to do gameplay that is you
know truly engaging for a kid and maybe trying to mix learning in it like I
guess there's some learning to be had in Angry Birds like you said like trajectories type stuff I
mean that's kind of interesting I don't know how much a one-year-old cares about
trajectory unless they find a slingshot but maybe you know yeah it's like the
bigger thing of like the consequence of like or just knowing that like there's
this spectra here like if you go like too far on one end and you go too far in
the other end next time you go in the middle or something.
I mean like there's some core concepts there.
So I guess my debate was how soon, you know, not that it's a big deal,
but how soon do I want to start introducing video games?
Because if you see like a one-year-old playing Angry Birds,
they can maybe play it, they can launch the bird,
but they're not really understanding it.
Yeah, that's true.
I mean, if they're enjoying it, okay.
Are they learning anything?
Is there something you could be doing that would help them learn more?
Right.
Does it matter?
Like, you know, these kind of questions.
Because when I was hanging out with my cousins a while ago,
one of them had a Nintendo DS and a Super Mario on the Nintendo DS.
And, of course, you know, when I was, you know, young, first, second, third, fourth grade,
I don't remember when we started having video games.
But we had to play, you know, Mario or whatever. I would get to the first level, second level, and then second, third, fourth grade. I don't remember when we started having video games. But we had to play Mario or whatever.
I would get to the first level, second level, and then die,
and there was no save games.
And I would just play over and over again, and it was really difficult.
Now I can play and like, yay, I can get to level five before dying.
So, of course, my cousin thinks like, oh, Uncle Patrick's amazing at playing Mario.
I'll have him beat this level for me.
But then it's like they
actually it doesn't help them because they observe me play but it's all like this subtle timing so
then every time they get stuck instead of like toughing it out themselves and learning they just
want to ask me like oh hey can you now be it's like no you know either I'm too busy and I don't
want to or like you know this isn't helping you me just keep beating these levels for you like
you know you're not getting anything out of it but, there was a long time before I was able to ever, like,
get a game to where I could beat it that wasn't a kid's game.
Yeah.
One thing that's kind of weird is I went back and played some old games
on the Wii Virtual Console.
Okay.
So, you know, went back and bought Mario and Zelda and stuff.
And I was actually much better at these games.
Yes.
I was, like, nine.
You remember them being, like, incredibly difficult.
And now they're hard.
But even more so, like, i remember being way better at them oh you were better before yeah
oh like i went to play and i think what it is i think i had more patience because the cost is high
right like if you know you're playing megaman like you're playing to beat the game you know
what i mean like when you're nine now when i Mega Man, I know that something's going to distract me in, like, half an hour.
Like, I know I just don't have the block of time to beat the game.
So I play, like, more reckless, and maybe that's part of it.
But, yeah, basically I can't get, like, even half as far as I could when I was a little kid.
Wow.
I think it's also, like, a lot of those games you needed to essentially memorize the level and the timing.
That's true, too.
I also don't have patience for that.
Yeah, so I'm comparing myself having not played for 20 years,
playing for the first time,
versus myself at the end of having played for six months straight.
Right, yeah.
Also, there is a thing out there on the internet.
People talk about games are becoming easier, right?
So you have saves, then continuous save, or walk away,
or you can just checkpoint
way too often or have too many lives.
Now the common thing in first person
shooters is not to have to go collect health
but you get shot and you just go hide behind
a box for a few seconds and then your
health is charged back up or whatever.
So I mean these things are making games easier.
I always feel like that was
sort of like a cop out because I think
what that does is
when you have these things like a lot of checkpoints and saves, what it does is it makes you spend more time focusing on like the real problem, right?
And less time like replaying.
So, for example, like Mario, we all have to play World 1-1 a million times, right?
But if we had, you know, a checkpoint every level level then we would spend more time on the harder
levels like getting the important skills you know yeah so there's really like a exclamation uh you
know a point to be made either way i guess at the end though you don't have the satisfaction of
i went through the whole game in one sitting right yeah no it's an interesting thing so
i didn't really uh have a amazing point there but just i was thinking about this kids and
games and whether my childhood playing games was good too much too little games yeah you know
what should it be now and i wonder like are we going to be those parents that like tell our kids
to go play outside like our parents did you know because i feel like you have to at some level like
you need to understand there's a world outside of games
and computers and video.
I think that's an important aspect.
But on the other hand, there's some parents
who don't let their kids have any computer time and game time.
And I don't know.
I feel like in order...
It's such a part of society now,
and getting a job,
especially if your child may show a predisposition
to wanting to get into something technical or computer-related.
Like understanding those skills are important and good to learn early and have time to practice.
If your child wants to listen to programming throwdown, you should let them.
That's a general rule that we've found.
Yes, yes, yes.
So talking about games, a new Kickstarter that was all the rage, I guess it's now a little bit of an old story, but it's okay.
The OUYA? Yeah. OUYA! OUYA! kickstarter that was all the rage i guess it's now a little bit of an old story but this is okay the ooyah yeah yeah this thing's pretty awesome um basically what they did is they took the android
os and um they created sort of an interface for the tv so it runs android it connects up to your
tv i guess hd HDMI or something like that.
And then it has these Bluetooth controllers that they look kind of like the Xbox controller,
like they're kind of designed to fit well.
And it looks like it's going to have dual analog sticks and all that.
And, yeah, the idea is you can play all these Android games in a TV setting.
And their whole mantra is bring gaming back to the living room because the idea is, you know, I mean, we
haven't seen a new Xbox in a while.
We haven't seen a new PlayStation. I think
a lot of these console companies,
they don't really know what to do. They feel like
things are sort of leaving the living room
and so much more money is to be made online
making these casual games for your phone
and things like that.
So this is sort of an attempt to create an open platform,
something that's never really existed in the console world,
and bring gaming back to the living room.
And it seems pretty cool.
Yeah, I like the idea of what they're trying to do.
I wonder if they haven't bit off more than they can chew.
I mean, they seem like they have some sort of experience in the field,
so that's good.
But I do agree that we kind of tried to get there right like this casual gaming thing
for your tv and in that way i felt that it was successful for me the week comes out when i have
a lot of people over to the house or something i don't ever play it when i'm just like me like i
want to play something because the graphics aren't very good it's kind of silly to be sitting there
moving around i don't know if that's me but i feel like the this uio console could be like it's like iphone games but on the tv and for your family or for
when friends come over and it really could be that fun and exciting thing especially if they
you know kind of embrace that as opposed to saying we're going to be a gamers game thing then i don't
i mean maybe it'll be good it could be there's a lot of good games out there for even the mobile platforms yeah i mean i think a couple of cool things or a couple
of things to know one is i think it'd be super cool if they somehow integrated the ouya with
your phones so like for example like a simple example might be uh you know it's some kind of
multiplayer like rpg game let's say and you carry your character on your phone.
And then when you go to your friend's house.
Yeah, you're both playing together.
Oh, interesting.
I didn't think about that.
The classic one is, and I think this is the one, though,
new Wii, Wii U, is it, I guess?
It's supposed to have tablets, and it's like you're playing football,
and instead of having the plays up on the screen,
you have to hide what button you're pushing.
Like you have it on your screen,
and so you can make the play or draw an audible or whatever and the other person has
no idea or you're playing like a board game right this is kind of cool you're playing a board game
and the board is on the tv but your pieces and your character are on your phone yeah that would
be your making selection yeah yeah so i think there's a ton of cool stuff they can make it to
where even a single player game let's say it was some game that had, like, it was, like, an FPS,
but there's, like, a strategy element to it.
So, like, maybe when you're at work, like, in your off time or whatever,
you'd be on your phone, like, doing the strategy part
so that when you come home you can, like, fight the battle
that you've been, like, preparing for.
You know, something like that.
Like, there's just so much potential.
That's true.
Or, like, the immersive-style games, they try to do this for a while
where, like, you're at work and you – maybe gets too much like farmville i guess but uh you know something
you have like a notification comes up that like hey you know your person is fighting on the lines
at home you know you need to like go in and drop into this mini game and help them out or go into
a little battle you know whatever and then when you get home you can like wage the war or whatever
but yeah or maybe like your whole family is fighting the battle at the same time so like
you might be playing the game and like uh your wife might be like on her phone at work and she
gets a notification like i don't know plays minigame to help out maybe this is just starting
to sound like too much like work than a game i don't know so so that idea to me is very appealing
and having low cost open hardware is good.
The thing that I skipped about, I guess, with the Ouya
is they're trying to have their game store, right?
And you go to them, but they're taking,
as opposed to like an upfront fee to go with an Xbox
and then a recurring licensing fee or whatever,
they're just trying to make it kind of the same app store model
and then requiring everything to have
at least some free-to-play element, which is great.
But I don't really want another closed
place for games. I want a console
that's like my PC.
I can just download whatever I want, play whatever I want.
If someone wants to make an open-source version, great.
I did that. And maybe you will support those
kinds of people can bring free stuff
and it not be a hassle or a problem for them.
And I really hope that's true.
I think that they said that all the games have to be free.
Like, the only money that can be spent is on in-app purchases.
Well, I think it's like, it sounded like a demo, right?
Like, you get the first level, and then an in-app purchase for all the rest of the levels.
Yeah, right.
So, okay, I mean, but what about somebody who doesn't want to pay anything?
And I didn't read it that closely.
Oh, I see.
But, like, what if you just wanted to release, like, hey, here's this crazy thing called uh trivopedia and i want to release it for you and you just want to sell it for you
know i don't want to name to it or something yeah like will will that be okay and they've said oh
without being rootable then the issue is always once you root it there's problems with subverting
the purchasing mechanisms right in the store so then they try to probably not let you be in the
store if you have it rooted. I don't know.
We'll see.
It'll be interesting.
So I haven't backed it.
Have you?
No, not yet.
One more thing before I talk about it is one thing they haven't addressed is the fact that
all of these games so far, like all the ones they list, they were all designed for a touchscreen.
They weren't really designed for a touchscreen.
So the controllers have a touchscreen on them, like a touch-sensitive mousepad thing.
Oh, really?
Yeah, yeah, yeah. See, how come they don't have any... that if you look there in the middle between the joysticks or whatever between the
analog sticks there's like a little pad and you're supposed to but there's a lot of people are
questioning like how are they going to do this so it's essentially a phone type motherboard in the
box you know and then but then these controllers are supposedly going to be nice perfect so are
they even going to be able to make like is the price too low? $100
I mean this is way lower than
any other, you know, I mean
Microsoft, Xbox I guess
is like $140
maybe or $200 on the low end
or something like that, I mean it's up there
and that's like they've sold loads
and loads and huge economies of scale
to get down to that price so
it'll be interesting to see what Ou are tries to sell the you know once it goes
commercial like once they're selling on their website or whatever what it'll
sell for will they be able to keep the $99 price point if so might be good
traction and then how many people need to be on the OUYA for it to be an
ecosystem worthy of targeting yeah so like you're a developer for iPhone right now.
Like, how many people, you're not going to convert everybody,
so how many people need to be on the platform for you to spend, you know,
however much time of your own money to port it to their system?
Yeah, exactly.
Yeah, it makes sense.
You really have to get that critical mass to get the developers online and everything.
Yeah, but, I mean, they've raised a ton, like $5 million, right?
Yeah, it's insane. $5.4 million. You and I mean, they've raised a ton of money, like $5 million, right? Yeah, it's insane.
$5.4 million.
You and I need to come
up with a video game console.
We need to make,
we need to make this app
for this console.
There you go,
a game for the Ouya.
Yeah, yeah, the,
you know,
you have to do something
all day game.
Oh, the one we're talking about.
Yeah, maybe we will.
All right.
In all that spare time
that we have.
Yeah, exactly. Yeah. So right. In all that spare time that we have. Yeah, exactly.
Yeah.
So this next article is, is C and or C++ worth it?
And I thought this was a really fascinating article.
You know, just to get to the meat of the article, they say, no, it's not worth it for almost everything.
And they show Java as an example.
But yeah, I mean, one thing that I noticed the article doesn't talk about is memory layout. So the example that the article gave is they ran through a loop, ran through an array,
and then added the previous element of the array to the current one.
So it was a simple array add operation. But I mean, where
a language like C or C++ really shines is in laying out this
memory model, either beforehand or laying out a memory model that's very efficient.
And then working within that model.
And so I feel like the article wasn't very
holistic, but it's still a really interesting read.
It's cool that Java actually outperforms C++ in this test case and many different compilers and things like that.
That's cool.
We'll talk a little bit more about Java performance in our section to come.
But I always see these, and I'm always a little doubtful,
because you really need a whole benchmark suite of really orthogonal tests.
Because we can probably find any number of things at which any language is faster than any other language.
If you have the whole search space of potential algorithms or simple programs, you just try one until it beats the language you're trying to beat and you
go, oh, I found it, you know, here. And it's like, yeah, I mean, you can spend time optimizing
for any one thing. But what I want to know is like, on average, if I just throw a random
problem or I know this is my typical domain set, how does one language perform against
another?
Yeah, totally.
And this, I don't know, this article is actually, you know, pretty short.
I mean, it is interesting that, you know, the typical Java slower than C++ thing at
this low-level task doesn't apply in this situation.
Yeah, I mean, one thing to sort of take away is that, you know, these arguments of, oh,
Java is really slow, like, you can't do this in Java because Java is slow.
Like, that argument isn't true, right? of, oh, Java is really slow. You can't do this in Java because Java is slow. That argument
isn't true.
Worst case, let's say
Java is 2 or 4x slower.
For almost any application
that would be fine.
A lot of times you hear people say, oh,
I can't use Java. It's too
slow. I have to do this in C.
That doesn't really...
For almost any
application, that doesn't make sense.
But yeah, at the same time, this very simple example also
doesn't prove anything either.
DAN GALPINERIRIEFFENBERGERIRAHIMIRABINIRABINIRA. It's
interesting.
And it's always interesting to read the comments on these
articles and see all the crazy optimizations people suggest.
And you're crazy, go away.
And all the way to very well-written, oh, actually, if
you wanted this suits Java better
to suit C++ better, you would do it like this
and nuances of various things.
It is an intriguing read,
and sometimes you do learn some really nifty tricks
that gurus in any language tend to know
about their language.
What is it, Donald Knuth quote
in The Art of Programming, right,
that early optimization is the root of all evil?
Yeah.
I'm summarizing.
Pretty much your optimization.
There we go, okay.
I found out, sorry to interject,
I found out Donald Knuth and I go to the same optometrist.
What?
Yeah.
Can I switch optometrists?
You could totally go to this optometrist.
Can you, like, ask for an appointment that's,
you know how, like, you have to have your eyes dilated
and you have to wait in the waiting room for a while?
Yeah.
Can, like, I ask for my appointment waiting to be, like like right when he's getting his eyes dilated so that i can
talk to him you could accept now these guys are on this uh what is it um optiplex or something
the thing where they take like that image oh yes you can't do it but maybe you could get it to where
like you find out when his appointment is, and then you just show up.
And you're, like, in the waiting room.
I think I'll get, like, a restraining order.
So, okay, we got a little off topic.
But, yeah, so that is cool.
Congratulations.
Yeah, you should totally go to this off topic.
It's a pretty cool guy, too.
Okay, I'll have to get that from you later.
Yeah.
So the next article is, I thought this was very interesting, engineering jellyfish.
So some researchers kind of grew, made jellyfish out of a combination of plastic,
and they grew some muscle on top of it and wrapped parts.
So I think it's interesting.
Now, as far as what they managed to accomplish, did they create life?
Well, I mean, they used some existing cells, so no.
And also, they tuned everything to behave to the materials they had at hand.
Like, they knew these cells act this way in this solution.
So then they kind of engineered the whole thing to do it. But it is still kind of cool that they managed to make this star-shaped device
which flexes and kind of, if you've ever seen a jellyfish move,
kind of like balloon and squeeze out the water to move forward,
which isn't efficient.
It isn't the most supreme way of moving.
It isn't really fast.
But it's kind of cool that they're able to kind of get these, you know, things to move in a way that really resembles.
And I always think that's interesting, this clashing of, and this one doesn't have a lot of, you know, it doesn't have a microprocessor or anything in it.
But there was another article recently about the people who programmed a robotic fish, which got accepted by the school of fish or whatever.
Oh, really?
And so like they thought it was able to like lead it at one point.
Wow, that's awesome. So I think this is kind of cool as we kind of learn more and more about animals
and what we can take from the animal kingdom and say like, oh, you know, this is –
even from – you always see those videos of people trying to fly like birds
and putting wings on their arms and trying to do this kind of stuff.
Even today we're kind of – people will look back on this jellyfish and say the same –
well, maybe not this jellyfish, but these kinds of endeavors, right?
Like, and kind of say the same thing.
Oh, these people are trying to.
Yeah, I think that, like, there's some domains where even just the simplest animal is so much better than our most sophisticated computers, right?
I mean, look at, like, image recognition or whatever.
You know, a dog is just better than a supercomputer. Right.
And so all of these attempts to sort of like integrate, you know, what we know of computing and and processing with, you know, the animal world and sort of how the brain works is is interesting because as we sort of bridge that gap,
I think we'll learn a lot on both fronts.
We'll learn more about neuroscience,
and we'll also learn more about computation.
And I guess I find intriguing this, I don't know, what is it,
cyborg-type stuff.
You know, you see these things where people put microcontrollers
on the back of cockroaches and control them,
and people insert brain inserts.
I mean, all these kinds of things are so cool,
being able to bring
stuff that much closer.
Originally, computers were in a giant room and
couldn't go with you.
Then now everybody carries around very powerful computers
in their pocket.
And then maybe soon on their glasses.
So always getting closer and closer and closer.
And those things are just kind of exciting and cool.
And the rate at which we're progressing is just kind of astonishing yeah yeah i mean i think that it would still be a
long time before we have what is it called strong ai i think that's the term so strong ai means uh
basically that it would pass the turing test for for day-to-day activities like that's like strong
ai so i think we're still really far from that right
but i think that that means that there's just it's just a completely open area and yeah and uh
if you can make progress there's just so many different fronts in which you can make progress
like vision is probably the one that's been explored the most but think about even just
like muscle mechanics right like your uh your muscles
are just a bunch of thin fibers that are put together but yet a robot has just a single joint
motor yeah and so like why why isn't a robot knee more like a human knee where it's like
like hundreds of these tendons that move together you know why is it just a hinge joint and so i
mean like i think all of these are interesting questions. And maybe this jellyfish makeup is a step in that direction, right?
Yeah, I mean, that is true.
Even if you had really good AI today, I mean, we still don't have a vessel to put it in that would allow it to really act like a human.
It would be obvious.
They don't move.
They're not capable.
Bipedal robots of today aren't really capable of moving in a way that fools you into thinking
it's human.
And even if they are, they're typically either tethered or have a short battery life or,
you know, aren't a full torso.
Just all these limitations.
So I wonder if it will end up being one of those things like, you know, we talk about
processing speed has outstripped, you know, kind of batteries.
That our batteries just haven't been able to keep up with how much power we need to be able to to run mobile devices the growths just don't match
and that's i wonder if it'll be the same thing that we'll look back and see how we've gotten
better and better at having machines that can do more but then like just nothing to put them in
yeah exactly everybody in other words everybody can't go into computer science yeah we need some
of you mechanical engineers and biologists and neuroscientists.
We need you guys too.
Yep.
I think it's time for Tool of the Buy Week.
Tool of the Buy Week.
All right, my tool is a set of three tools.
Wait, that's cheating.
It's totally cheating.
Now you're just making it so you can look better than me.
But they're all basically the same.
And I'll talk about all three of them briefly so so I'll talk about the Windows ones first basically all three
of these tools have the same purpose which is to bring the awesomeness of
like Unix and like all the cool packages and the GNU packages that people have
made and bring those over into other operating systems so sigwin which actually i think is short
for like cygnus windows which is like cygnus is the company that i think is now bankrupt or something
but they made this is actually uh what's called posix so a little bit of history um unix runs on
top of this thing called posix which is or maybe posix runs on unix this thing called POSIX which is or maybe POSIX runs on Unix
I don't quite know this all happened way before
either of us were born but
essentially POSIX
is the thing that implements a lot of the
functionality of Unix like fork
which is a function which
you know takes your
process and splits it into two processes
while keeping all the variables
in both processes so
it like makes a copy of it so all these like very primitive functions that comprise like the unix
layer right above the operating system right above the kernel so that posix someone went ahead and
implemented that by using windows calls so when you, Cygwin turns that into like a
Unix, or sorry, like a Windows, like the create thread function and then copies
over all the variables manually or something like that. So they implemented
all the POSIX routines in Windows and then once they did that, now for programs
that are built on Unix like GTK for example, they will just compile on Cygwin because they don't know any better.
The functions just do what they're supposed to,
and to these higher-level programs, it just works.
Which is a beauty of something like POSIX.
If you really restrict, here's, in essence, an API you're programming against,
how strong that can really be.
Yeah, totally. So Cygwin is awesome. And there is one problem with SigWin, which is,
you know, you have this POSIX code, and it's wrapped in what's called the SigWin1.dll.
And, you know, as I mentioned, all of the code calls functions in this wrapper, in this
intermediary layer. So let's say I was to make a program with Cygwin,
like Jason's program, and I wanted to give it to Patrick.
I also have to give him the Cygwin1.dll,
which doesn't sound like that big a deal,
but there's actually a license restriction.
The Cygwin1.dll is GPL.
So which means if I was to give Patrick Jason's program,
I also have to
give him the source code.
And so, that can cause issues, you know, depending on your environment and things like that.
The other issue that I've run into before with Sigwin is that although it's great
to cross-compile and it works really well, like, it's an amazing tool and it helps
a lot of things, is that you can end up with trickiness.
You think you're running in Linux sometimes.
And so, if a program is doing something which normally takes 10 milliseconds in Linux,
but it might, because of all the extra work
that has to be done in Windows to simulate it,
it might take 10 seconds or something crazy.
You can end up with programs that are just completely unusable
or just take a really long time.
Because, for instance, Fork in Linux
is a completely different kind of operation
than creating a new process in Windows.
Yeah, you're totally right.
So in general, so let me get to the alternative signal,
which is called MinGW, which I think is Minimalist GNU for Windows.
And MinGW is similar, but it actually works on the compiler level.
So what that means is, you you know I write my code I have
access to all these cool posix functions but then what they do is that compile
time they dump it all together into an executable that completely is
self-sufficient so you don't need the sigwin DLL it's not main GW isn't GPL so
you're not like you you're okay there.
And in general, the executables are faster.
So the bad thing about Ming GW is it doesn't have this package manager.
Like with Sigwin, you could just run the Sigwin package manager and say, I want GTK, and it'll do everything.
A couple of clicks, now you have GTK.
Ming GW is more of a compiler, so it's not
really meant for that kind of thing.
In general, use Cygwin when you want to run
Unix programs and use Ming GW when you
want to make programs from the Unix
libraries.
Yeah, that's the way I kind of use it.
So that's for Windows.
Now, for Mac people, don't feel left out.
You can totally use GNU programs.
You can totally use your GNU Cache and GNU Chess and GNU Go
and all those cool things and Inkscape and GIMP and whatever
by using MacPorts.
And so MacPorts is a... Jeez, how would you describe MacPorts. And so MacPorts is, jeez, how would you describe MacPorts?
So I think it's a little bit of a fundamentally different thing than what happens on Windows
because Windows isn't really based at all on a Linux-type POSIX environment, whereas OSX kind of is.
So OSX is just kind of providing the right kind of compliant libraries to kind of get at.
This is my understanding.
I'm probably messing this up.
No, I think that's right.
Get at the understanding that underlies.
Like here's how to do the thing you would do in Linux but on OSX.
Yeah, I think that's exactly right.
So Mac ports is basically just changes to like build systems and things like that, which are sort of Mac-specific. And it sort of takes into account the fact that some things already exist on Mac
because it's also a POSIX-compliant system,
but then some other things don't exist or have to be rebuilt or something like that.
I guess the other thing is making sure that the right libraries are there
because it doesn't natively know how a Mac doesn't natively know how to
get all of the right libraries associated with it.
So you kind of need a way to say, hey, I need to go grab all these extra libraries that
didn't ship with my computer.
Yeah, exactly.
Yeah.
So yeah, these are great.
If you use Windows, you should definitely be using Sigwin.
If you're a Mac guy, definitely check out MacPorts.
If nothing else, it's fun to use these programs and just browse through all the packages.
Because there could be some really interesting tools that you've never heard of
or maybe new programming languages that you want to try that are already there
that you just couple of clicks and you can get them on your computer.
And I should probably correct myself before we get lots of not happy email
about saying OSX has Linux underneath.
And this is where I'll show my, it's really BSD.
Oh, really?
So I think OSX has BSD underneath it.
And even then there's some other squirrely stuff.
So please just like anything that was said in the last, it
wasn't quite right, just please forgive us, or forgive
me anyways.
That's our first mistake ever.
Man, that's a milestone mistake number one.
Yeah, number one.
Yeah.
So my tool of the bi-week is far less technical than that.
So you share.
And I have a Google TV, a Logitech review at home.
And I had some movie files on my
computer and I wanted to stream from one to the other because my my computer is
hooked up to my small monitor in one room and I have a nice TV in the other
room and the Google TV is hooked up to that and of course Google TV works great
for playing Netflix and other stuff and they, and this is true of many now actually TVs
themselves and things like we talked about last week about
Xbox Media Center, even running on an Apple TV, that
you have the ability to stream from a DLNA server.
And so I tried to get various DLNA servers set up on my
computer, and I got some to work but most of them seemed
to want to go into GUI mode, require lots of
setup but I was able to get
UShare installed so that I could kind of configure it
and manage it over just SSH
so that I didn't have to keep going into this
computer that wasn't always plugged into a monitor
and so now it worked
great, like just right out of the box. I mean
it doesn't do a lot of the
DLNA servers try to index your files
and say, like, oh, here's movies with actor.
I don't know an actor.
Give me an acronym.
Tom Hanks.
Tom Hanks.
Tom Hanks.
You know, here's all the movies with Tom Hanks in them.
And, like, let me go fetch all this extra data.
That sounds cool, though.
That would be cool if it worked.
And then if it doesn't work, it kind of, like,
seems like most of them just default into giving up or whatever.
So I just wanted to have it fairly well structured in a
file folder structure that I wanted.
And yousure has, I think, this other option to do this
indexing and do awesomeness.
But I didn't really want that.
So I just turned it off and just like, please just give me
so when I go onto my Google TV, I can navigate to the
folders and then just select the video file I want, and then it does the transcoding for me.
So because Google TV only does a very limited set of codecs, the Ushare knows how to convert it using, I think they use FFmpeg by default.
Convert it over for me so that it just plays, and then it's like, this is lovely.
And it starts up really fast and goes smoothly, and I haven't had any issues or any files I came across yet that wouldn't play.
And so that made me very happy. So that's why they get a recommendation from me that's you share
nice so so just so i understand because my my media setup thing is a disaster i need you to
come over it need to hire you like a time sink but so i have a desktop which has a bunch of movies on
it uh in one room then i have a laptop connected to a monitor in the other room and right now I just do this painful
like I'll copy the files over and then run them or I'll have like an NFS but it
doesn't quite work right because it's not like a true media server so like
there's all sorts of latency and sometimes a video stutters so you're
saying I can install this on the desktop in the living room,
which doesn't have anything attached to it.
Right.
And then the laptop, what would I install on the laptop?
So on the laptop, there's all sorts of what you want is a UPnP or a DLNA client.
So there's all sorts.
I think VLC will even do this and connect up to it.
And the nice thing is if you have a laptop,
you actually shouldn't need to do any transcoding
because your computer can play everything.
So it'll know how to stream it.
But the DLNA servers, and I believe you, Cher, will do this too,
it'll also detect your link speed.
So it knows, like, even if you understand the codec,
if the rate is too high, it'll downcode it for you
so that it can stream reliably across the network.
Wow, this is amazing.
I mean, this is stuff that's done all the time for YouTube videos, for Netflix.
I mean, this technology is out there.
And it's just, you know, sometimes it's a little complicated to get set up.
Yeah, yeah.
And so I kind of ended up taking the shotgun approach
and installing, like, five different, you know, UPnP servers
and seeing which one would just work nice with my device.
And then you use VLC as the client?
So on mine, I have a Google TV.
So Google TV has, like, a specific, like, here's the program you run. Or if you have a TV or the client? So on mine, I have a Google TV. So Google TV has like a specific, like here's the program you run.
Or if you have a TV or an Xbox or a PlayStation 3,
they all have like these are the program you go run
and select the file you want to play and then it will stream it for you.
But on a laptop, there's lots of them.
So like if you're running Windows, like Windows Media Center will do it
or just Windows Movie Player.
Windows.
Okay.
Whatever the Windows Movie Player thing is.
Yeah, yeah. Or like I said, I think it's whatever the Windows movie player thing is. Yeah, yeah.
But, you know, or like I said, I think VLC will do it.
There's also Xbox Media Center, which we talked about last week, is a UPnP client as well.
And we'll give you the nice, what they call, 10-foot display.
So the ones with the big words and not the normal file menus.
So you can navigate with large categories and select it on your remote.
Oh, that is totally cool.
And then be able to play it that way.
Nice. That is awesome. I'll have to check that out. So if it works, you'll have to report back and let be able to play it that way. Nice.
That is awesome.
I'll have to check that out.
So if it works, you'll have to report back and let us know.
Yeah, next week.
I'll try it this week.
Or you can email me and say, oh, it's not working.
What happened?
So two weeks from now, either we won't have a podcast because Patrick hates me,
or we'll be talking about how I got this media center set up.
Anyway, check it out.
That's you share.
Yeah, it looks awesome.
Yeah, I'll definitely do that.
Folks at home should, too.
Time for Java.
Java. This is like
trying to swing a sledgehammer.
I mean, we probably won't be able to cover
everything. Yeah, I think we already agree. We're going to call this
Java Part 0.0.1.
Java Micro Edition.
So this is going to be an introduction.
We're not going to try to cover everything.
And we know we'll come back and revisit some more of these things later.
So Java kind of has an interesting history.
I mean, everything has an interesting history, I guess, if history is interesting to you.
The interesting thing about Java is that the history was, like, when we were sort of learning,
when we were learning as much as possible about computer science,
like, when we were learning more per month than ever, Java was like the language that's a good way to put it yeah
it was like right in the sweet spot of for me like you know right when i was kind of getting
to college java had just come out of its infancy yeah you know and it was like you know right when
it first came out i didn't really know what's going on i didn't know i heard about it but then
you know like as i began to get you know into late high school and college i began to see like people wanting to use java and
think about java and talk about java yeah it was the hotness yeah yeah that's right the hotness
so their their slogan which i think you know it's still kind of one of the best strong points which
is amazing that we kind of take it for granted that somebody can set out to do something and
then actually do it so java had this write once, run anywhere.
That was like their slogan or whatever.
And, you know, without getting into too much debate, it took them a while.
But I think today, you know, regardless of everything, if you just ignore that,
look at that motto from 1995 and then now like 2012 and you say like, hey, Java, where's it running?
And Java runs on all sorts of platforms and devices.
And, you know, I don't know how much the right once
part comes into that,
but they really are, you know,
making it so that it is so much more pervasive
than a lot of other languages ever reach.
Yeah, totally.
Yeah, I mean, think about all the pain
that goes into like deploying an app, you know?
I mean, you have to deal with,
you know, first you have to build it for every architecture and you have to deal with all these
like 32 bit 64 bit issues you know if it's big indian little indians so not only do you have to
build it for these different architectures but sometimes you have to change the code depending
on which one um like god forbid you try to like you know mem copy a structure straight to a file
or something because that'll never port over right so there's all these, like, you know, mem copy a structure straight to a file or something because that will never port over, right?
So there's all these disasters.
And then, you know, you finally get it to where the code is okay and the code runs the same on all these machines.
Now you have to deal with, oh, this person is missing this library that you expected them to have installed.
So now you have to carry over, like like a virtual machine, like virtual box or
something that runs a completely bare bones Windows and run your program there and make sure that you
don't have some DLL that you didn't realize you had that no one else has, right? So you have all
this drama. With Java, you can, you know, using Eclipse or NetBeans or any of these IDs, these
tools we'll talk about later,
you can just click on your Java code and say,
give me a runnable jar, which is, what is it, Java Archive or something?
Sounds good. I'll look it up.
You just say, hey, give me a package of, like,
take this code and make it run on any machine I want.
And it will do it.
And you'll end up with this one file. You can give it to your friend as long as he has Java installed which now the install base is extremely high.
He can just double click the file you gave him and it will work.
And you're just bypassing all of the things that I mentioned before.
So I mean this is huge.
Now we take it for granted but at the time this was just incredible that you could do something like this.
DAN GALPINIERI- Yeah, I feel like there's a lot of
legacy that goes into Java.
And whenever we talk about it, ultimately you kind of talk
about it from one aspect.
There's the individual programmer.
There's the enterprise team.
There's the person learning to program.
There's all these different things.
And so you kind of have to take one view at a time.
But a lot of early experiences of Java
kind of maybe had some missteps
or people have bad memories or bad taste
or somebody who's really good at C++,
Java looks so close to C++ in so many ways
that you're kind of tempted to just do things the same old way.
And we talk about that a lot on this podcast
that when you use one language and then go to another,
you can bring a lot of really interesting things.
But if you just try to shoehorn one to the other, like,
here's my C++ code, I want to line for line, just copy it into Java.
Well, you can't expect that it's going to be the greatest ever
because you're not using it the way it's meant to be used.
Yeah, totally.
And then one really cool feature of Java was this notion of applets.
So Java in 1995, it's coming out.
And this is right around the time, or at least I remember,
the Internet was really coming into its own
and really starting to get a hold and become a serious place
that people did business on.
And it was really becoming what kind of it is today.
And so these applets were programs you could run in your browser.
Instead of having to even send your friend a JAR file,
you could just host it on a server,
and he could just go to this page and have the applet run.
Yeah, I mean, and this is just mind-blowing, right?
I mean, so this is before Flash, before any of that.
So, I mean, basically you had either HTML or you had applets.
I mean, that was pretty much it.
I mean, you could do some clever things with like
css 1.0 or whatever so you could have like the font changing you know there was javascript tag
yeah yeah you could do the blink tag there was like some basic things you could do with javascript but
you know it was too slow i mean javascript is like 30x faster than it was back then so you
couldn't really do anything fancy and uh and then applets came out and it was like oh my god i can do
whatever i want like i can just draw pixels to the to the screen if i want on someone's website
and that just like blew people's mind one of the most popular applets remember it was uh
it was like you would give it some text and it would create this like reflection but the
reflection was shaking as if it was like oh i don't think i've ever seen this yeah yeah that
was like all these websites had this applet
where it's just like the name of the website and then the name like inverted.
It was kind of like I always felt like I had slow internet for a long time
until I kind of went to college.
And so like whenever I went to a page with Java, I knew it
because it would just like take that much longer, you know, to load.
But I think the other interesting thing that Java really addressed, and this might
be me misremembering in nostalgia,
but, you know, because
Java was, from the start, kind of heading
towards the internet, had this applets,
they really had to address security, you know,
like, how do we really make things secure
since the browser is going to let
somebody run arbitrary code, just
kind of like without permissions. They don't even have to download
something, you just go to a website, and all of a sudden code's kind of running and you know they've
kind of iterated through that and done some stuff but really thinking about how do we have a good
sense of security and how do we balance that with needing to access a person's computer but guarantee
that those things we're doing are safe or allowed or okay yeah you know one interesting like side note so sgi did silicon graphics
incorporated did like a bunch of like crazy pioneering graphics research like like when the
so nintendo 64 when that came out um there was this weird thing it wasn't quite a triangle it
was like a scan line like weird polygon thing and they were using that for doing like 3d rendering
and it was like totally kind of crazy off the wall and then they they using that for doing like 3d rendering and it was like
totally kind of crazy off the wall and then they they tried that they refined it then they switched
to the polygon model they just all this pioneering research and then they died you know and it's sort
of like this huge investment and the company dies uh or they got bought or something and i feel kind
of bad because the same thing happened to Sun. It's like they made Java.
They did all this cutting-edge pioneering, like groundbreaking stuff and then they just got bought like almost immediately.
It's kind of like –
Well, it wasn't exactly immediately.
When did they get bought?
It was fairly recently, right?
So I mean I think they had a good about like 10 years, 15 years or something.
Was it really that long?
Yeah, and then Sun did a lot of other stuff as well, right?
I think they might have existed before Java doing other things.
Oh, really?
We should have done, I guess, more research into Sun itself.
But yeah, because they used to make server hardware and stuff as well.
Was that before or after Java?
I don't know.
Well, yeah, Solaris has been out forever, right?
So, yeah.
But even SGI has been out forever, right? So yeah, but, but even like SGI has been out forever too,
but like the company's like,
usually like,
it seems like they come up with awesome stuff.
And then like a few years later,
I don't know.
I don't know why that is.
Maybe,
but sometimes that's a good thing,
right?
Like sometimes it means they did really well and somebody was willing to pay a
lot of money for them.
Yeah,
that's a good point.
So,
so that can happen.
But yeah,
so I mean,
Java really did kind of was the first kind of mainstream language
that addressed a lot of new paradigms as it were.
You know, it kind of came out and it's like C++ had done the object-oriented thing.
So like now Java is going to do it.
Java is going to do it kind of in its own way and really embrace this, you know, object-oriented
model and take it kind of to a new level and, you know, and really try to meet the needs of a lot of people.
I mean, there are programming languages that did
object-oriented arguably better in a different way.
And a lot of them got acceptance in niche ways and
kind of specific.
But to make a mainstream acceptable programming
language requires some compromises to try to meet
everything that you are trying to do.
And it's kind of amazing that Java was able to do that as well as it did.
Yeah, totally.
And the cool thing about Java is they kept it very close to C++ from a syntactic point of view.
So you could think of it as a lower barrier of entry because a lot of the code looked the same.
But they made sure it was sort of pure.
You know, like C++, it's kind of clear that the object-oriented is built on top, right?
And that C++ is sort of built on top of C.
And it's like, it's sort of really evident.
Like, for example, the way, like,
callbacks are implemented in C++.
Like, imagine if you, like,
or, like, even, like, member function pointers.
Like, if you want to have a function pointer
to a method inside of a class
in C++,
that stuff's a disaster, right?
Trying to do that is just a nightmare. Bang your head against
the wall. It's because it's sort of
C++ was
sort of trying to do the whole
classes thing, but still
interact completely transparently
with C. And so by
Java sort of separating itself from all that and saying
we're not going to have these native
arrays and all these things and
just functions hanging out
like global functions. We're not going to do
that. By making these
restrictions and by
making a brand new language, they were sort
of able to make it a lot cleaner.
Java also sticks out in my mind as
coming out with updates.
So I guess because C++ was kind of written,
and it wasn't really a company that kind of owned it, right?
This is our thing.
We're making it.
It was good and bad.
So Java came out.
Sun owned it.
They had made the virtual machines that the code.
So we should talk about this a little.
So in Java, the code compiles to, like something like a jar to you know these class files and these things are compiled against
not your hardware but against the java virtual machine right the java virtual machine is written
to basically run on your hardware and run the java program on that program on your hardware yeah so
all those things i talked about before like the 3264 bit and the Big Indian, Little Indian,
they dealt with that when they made the virtual machine.
And so now you don't have to deal with that
because you're sitting on top of like an abstraction.
And so when they kind of made all of that, right?
So like they owned the virtual machine in a way.
They, you know, kind of defined the language.
They were able to make kind of updates, add features.
And if you look at Java today, there's a lot of,
like if you try to just compile a Java code written today
against an early Java, I don't think it'll work.
So much stuff has changed.
And just even basic assumptions have changed over time
and things have gotten optimized and better
and adding new features and kind of working on the rough edges.
And I feel like they were able to do that because they could.
Because they owned the stack in a way.
But that didn't stop.
In the licensing thing, we're not lawyers, so we're not
going to really talk about it, because it gets really
complicated and gets into it.
But even from fairly early on, there were people who wrote
other virtual machines.
So Java compiled to this bytecode.
But if you could write a program that would interpret
that bytecode and do stuff, go ahead.
DAN GALPINIERI- Yeah, I saw something
interesting the other day where someone wrote an LLVM,
like interpreter for bytecode or something like that.
Actually, it took in bytecode and it output C code.
So it was like this Java to C compiler.
It was kind of crazy.
DAN GALPINIERI- But I mean, yeah, the byte code is
essentially machine code, assembly code, for a known
virtual machine that isn't a real PC.
And so that kind of concept in doing that, that's really
intriguing, and people could do it.
So in theory, if you think you can write a faster virtual
machine than Java for a specific instance for your use
case, you could do that. And again, ignoring all of the licensing and problems and
copyright, but this is what you hear about when people say
Android runs on Java.
So on your phone, when you run an Android program on an
Android phone, it's not running on a
Sun virtual machine.
It's running on one that Google wrote that to the program kind of looks the same.
Right.
Yeah, exactly.
And they're able to do that and make it because of some of the decisions that Sun made.
And also, I mean, Sun did open source Java in 2006.
So even though they own it and they can still continue to make updates,
it gets so subtle.
I still don't understand exactly the problems.
Like a lot of people are unhappy with the way they open sourced it.
But other people are saying like this is a groundbreaking step that they did open source it and make it available for other people to use and modify and build on top of.
But needless to say, I mean, they made an effort.
They did some open sourcing.
They revealed a lot of stuff.
People can come in and make changes and use it and kind of change it for their own.
And, you know, that's kind of an interesting thing, and it's kind of cool.
And, you know, Oracle bought Sun, who was creating Java,
and some things seem to have changed in the way that they will agree or let people do.
But ignoring that, I mean, I feel like Java has really changed a lot from the way I remember it,
like what it used to be used for and where it went, and then what it is used for today. I guess that speaks to the flexibility. It hasn't fallen by the
wayside. Yep. And I think that a lot of the research in just... So one thing Java has,
and we'll kind of touch on different things as we talk about it and keep the dialogue going,
is a just-in-time compiler. And so this is a little bit complicated, but basically the way it works is, you know,
Java will look ahead. So
the virtual machine is sitting there
executing your code, and it's doing
like if statements and going to different places.
It's executing the already
semi-compiled version of your code. Right, yeah.
The version in Java assembly.
Yeah, the bytecode. Yeah, so it's executing
the bytecode, and it can look
ahead and say, hey, you know, you don't have an if statement coming up for a while.
Like the next 30 instructions, they're guaranteed to run.
Let's say the next 1,000 instructions before you get to an if or a branch.
So let's see if we can do something clever.
Like maybe these 30 instructions, they're all ads, And they're all around the same place in memory.
So we can send it to what's called a SIMD, single
instruction, multiple data.
We can send it to a SIMD processor.
All 30 of these instructions can go to a processor that can
do it all in one step.
And so Java could do all these really clever things.
And do that at runtime, based on the
hardware it's running on. Yeah, exactly.
And do it right a little bit ahead of
just in time. Just a little bit
ahead of your program.
So, a lot of
that research came about because
the virtual machine was open source and people
could hack it and do all sorts of
interesting things. University students could
go through and make all sorts of
crazy optimizations
and do a lot of experimenting. And Java has always been really synonymous with academia
since the beginning. Yeah. I mean, when I was in college, that was the de facto language of
algorithms and data structures, those classes. That's what we learned. We learned in Java.
And then it seems like today they've backed off a little, some of the universities, to acknowledging that C++ still has a place and there are a lot of companies still using it. And
so teaching more C++. But the only course I had where you needed to know C or C++ was operating
systems. Yeah, I was the same way. And even in operating systems, we still wrote some Java for
a lot of the multi-threading example stuff. But for like all of the, a lot of the very,
very low level stuff, we had to write C, which was many people's first time of ever using c yeah that's a scary experience yeah i remember the
first time i saw uh in c somebody casted like uh he had a character array and he wanted to put a
struct in the array uh because the character is just representing a block of memory. And he casted the character array to like a struct pointer.
And I was like, you can't do that.
I was like, what's going on here, you know?
And so it's because Java is so much more strict, you know.
But from its strictness, I think, is sort of an elegance.
I actually kind of really like that part of it.
And one of the things which, you know, I guess we'll get to later is Java is really
strict about you doing exceptions and making sure things are the right type and things
like that. And I feel like that for new, for people who are new to programming, that sort
of builds the right habits, you know? So I feel, I still feel like Java is a good language
to teach like at the university level.
Yeah, I agree. It's kind of interesting to see because I learned C++ first
and then did most of my learning in Java
at the university.
But still, I came into it
with thinking about things
in terms of pointers and memory layout
and the kinds of things
that you get drilled into in C++
because if you mess them up,
you have to learn them early.
And if you mess them up,
the end results are really painful.
So this kind of memory management versus comparing that to somebody who learned Java from the start
and then tried to write in C++ and really struggling with pointers and pointer indirection.
So it's kind of there's pros and cons to both because I do things in Java sometimes.
It's like you don't really need to do that because it handles it.
But it's because I'm used to it.
I need to do it this way because else my C++ program is going to blow up.
Yeah, exactly.
So even to this day, I carry forward some of the things.
So it's interesting to talk about what language you should learn on
that will be easy for you,
help you get through the most important and interesting parts,
and then leave you set up for the best place for your future.
Yeah, I mean, a professor at my old university was asking me the other day if
he should teach Java or Python to new students. And I still felt like Java is the way to go,
because with Python, you have sort of a lot more freedom. But you know, when you're new,
like a lot of that freedom you can use to sort of make bad code. So Java sort of forces you to
follow a certain structure.
And even if the structure, depending on what program you're writing, isn't good.
Like let's say you're writing some kind of control loop
or some kind of thing to generate reports.
Maybe Python would be the way to go because you want to constantly be changing it.
But still, to write it in Java and follow a certain framework
can sort of give you the discipline you need to
then go to other languages and not like make a complete mess of it, you know.
Except Perl, you'll always make a mess if you're writing Perl.
Yeah, it is true.
Sometimes that rigor does, you know, it's like you can always write the class and talk
about like, hey, how am I going to define this class and what are the interfaces going
to be? And writing in something like Java
or even C++, well, fortunately that
versus like Python, you more get
into the idea of just scripting.
Like, I'm just going to start writing a script to do this.
And then, oh, wait, I actually do need an object.
Well, let me go create.
It's kind of like, you know, growing up in school, you always told
you got to write your outline before you write your paper.
And I feel like I always did terrible at that.
I always just wrote the paper and then wrote my
outline based on what the paper was.
But I do appreciate what they were trying to get into me and
what I should have done and how it would have been so much
better to sit down and think about stuff.
And so sometimes object oriented stuff does help with
that, kind of giving a structure and
outline to your code.
Yeah, yeah, totally.
So some of the features that Java has, we talked about some
of them already,
but generics.
So, what is the idea of a generic?
That sounds like a really bland topic.
Yeah.
Yeah.
Yeah, generics is, that's a tough one to explain, but I'll give it my best shot.
That's why I asked you.
Oh, nice.
It's totally awesome.
So, first, I guess the best way to explain generics is to give a use case, right?
Okay, let's go.
Let's say you wanted to create a list.
So not you want a list in your program, but you actually want to create the concept of a list.
Like you want to make a list class, right?
So you don't want to have a list of integers.
You don't want to have a list of integers. You want to have, like, my class int list, and then, you know, under the hood,
it could be an array of integers that, you know, resizes or something like that.
And then have another class called double list and a float list and things like that.
What you really want is, as we talked about in the C++ podcast, you want basically templates.
So you want to say, this is my list of type e
whatever he is and then later on you want to say okay I want a list of ints I
want a list of you know doubles on a list of floats and your custom classes
yeah yeah a list of like JSON objects or whatever and you want the system to be
able to understand what you mean. So generics are different than templates,
but generics, in the end, give you the same end goal.
It's trying to get at the same thing,
but doing it in a different way.
Right, so to explain the differences,
in the case of templates,
what the C++ compiler will do is,
if you say, I want a list of doubles,
the compiler will say,
have you ever asked for a list of doubles before oh you haven't okay let's take all the
list code which is you know list of e which is where he's my template let's
make a copy of this code and everywhere I see e I'm gonna replace it with double
with literally just like a find replace on that copy of the code and then I'm going to use that reference so you actually have like duplicate copies
of the code one for each type that you're using in the case of C++ now in
the case of Java with the generic it it actually works kind of differently so
the instead of being that sort of low level,
it will still have the notion of E all the way through.
But when you go to create a list of, let's say, doubles,
the compiler knows that this specific list,
if you say list double Patrick list,
Patrick list push 1.0 or something like that.
So it knows that Patrick list is a double list and it's not an end list but it still only has
one copy of the code so this is kind of like it seems like it's like really
pedantic like it's sort of a nuance but the end result is that it's you pay a
performance hit so generics are not as fast as templates. Like in C++, you could use a template,
and it's like universally better.
But in Java, in the case of generics,
you are paying a little bit of an overhead price there.
That was a good summary.
It is one of those things that is subtle
in what exactly you're allowed to do
and not allowed to do at compile time versus run time
when you instantiate an object.
It gets very subtle and the differences,
but I think you summed it up.
In the end, it tries to get at the same goal.
How do I write code that applies
to many different kinds of objects?
Yeah, the only other subtle difference
between generics and templates,
with templates, you can put anything.
Like you could have a template because it's just going to do a find replace, right?
You could have a template and then template put one.
So you could have, for example, let's say you had a class called array.
Actually, boost has this class called array.
And the template parameters, one is the types.
You can put int, float, whatever.
And the second template parameter is literally a number.
So you can say, like, boost array.
You know, this is in C++.
You can say boost array bracket int comma 100.
And it will create an array of size 100.
In Java, you can't do that.
So all of the, you know, quote, unquote, templates, all the generics in Java have to be types.
And so that's a subtle difference, but it can have, again,
like some implications on performance.
So, all right, that's generics.
Why don't you cover garbage collection?
So garbage collection in C++, if you – so there are two kinds of memory, right?
There's static and dynamic.
There's I know I need to hold the value of an average of a number of items in a list.
So what is the average of all of the numbers in my list,
which are heights of various trees in the forest?
I like to think of colorful examples.
So all the heights of all the trees in the forest.
But you don't know how many trees are in the forest when you write your program.
You want a program that can work for any forest, maybe a big forest,
maybe a small forest, maybe a park, maybe your backyard.
I don't know if your backyard can be considered a forest.
But anyways, you want to be able to count up and average all of the heights of the trees.
So you know you want a numerator and a denominator,
so you can do the sum of the heights divided by the number of trees.
That's how you're going to get your average height.
So you know you need these two things, and you know you need to store the output. So those are your static variables, the variables you know in advance you're going to get your average height. So you know you need these two things, and you know you need to store the output.
So those are your static variables, the variables you know in advance you're going to need.
But then dynamically, you need to be able to say, I'm going to have 100 tree heights.
I'm going to have 5 tree heights. I'm going to have 1,000 tree heights.
And so in C++, this is done with the new and delete.
So when you say at runtime, somebody has to tell you, okay, I'm passing you in a list
and you go, okay, well, how long is that list? Oh, that list is a thousand trees. You know,
okay, well then I need to create a thousand heights item slots and I go create them. And then
that I do that with the new. And what it does is instead of where static memory comes from one
play, we won't get into the super big, but like one operating system has one pool of memory for
static and another pool for dynamic, which is pretty big.
And so it goes and grabs you some random chunk out of this big pool and gives it to you and
says, here you go.
Here, you can stick all of your trees in this random chunk of memory that I gave you.
That's contiguous memory.
It's all in a row, but it could be anywhere.
It doesn't give you a guarantee about where it is.
And then you get that.
And if you can't get it, you're out of memory. And you
typically, that's what you get out of memory exception, because there's no memory for you to
dynamically allocate. So you allocate that memory, then you fill it with your numbers, you do your
division, and then you need to make sure to free it. If you don't free it, this pool of memory
that's for everybody across the whole operating systems, dynamic allocations, then they can't use it. And it'll just stay,
the operating system will just assume that's always being used forever, you know, and that
it's, it may be, you really need to keep it there for a really long time. And so it won't go and
free it for you. And so if you have a program that runs for a long, and then the operating
systems will get smart and kind of say, oh, your program's dead. Like I can go free it or try to do
various clever things. But ultimately if your program's running for a long time and you continue to call this function
over and over again, you'll keep what's called leaking memory. So the idea
in Java is say, well that's a pain, people inevitably forget to free all of their
memory, they don't do it in the right time, you free it too early and then
somebody else uses it, and then Jason goes to read data that I told him that I
put there and in reality it's no longer there and he reads something else he's
not supposed to. So in Java they get around this by trying to say instead of this we'll handle all
of the allocations for you. You just go use something and when you use something you say
new or whatever and it'll work but then what we're going to do is use various mechanisms such
things as like reference counting. So how many things do I have that store the address of the
data? So I have five variables that all point to the same data.
Well, Java's virtual machine will keep that data marked for
you until there's not, you go five to four to three to two,
as your static functions are ending, as your program's winding down, whatever.
And you begin to not need these variables, it's called what goes out of scope.
So when they're no longer,
there's no way your program can need it in the short term.
And once that goes down to zero,
that means nobody is using that data anymore.
Nobody's pointing to it.
So then Java can do what's called garbage collect.
It can go through and say,
everything that no longer has anybody pointing to it
or using it, I can free.
And that works great.
You don't have to remember what to free.
You don't have to remember who's using what.
Java just kind of handles it all for you.
The issue is that you don't have control
over when that happens. And later
they really tried to address this, and maybe even from the
beginning, but it's just this complicated issue of
if you're trying to do something and you really need it to
go now, and Java decides
like, I'm going to garbage collect now, then
you kind of are stuck waiting until it finishes garbage
collecting because it's a really slow process.
Yeah, because think about it. Java has to go through every object you've made in your entire
program potentially and say like which of these objects are you do you not need anymore and that's
an expensive process yeah and so that there are great amounts of research have been done to make
this better and faster and do all sorts of awesome things to make this so like even now there's
different levels of garbage collection, right?
Like a very shallow one.
Like, let me just look for things that are really obvious.
And if I free up enough for you, great, then I'll stop.
But then if, like, I'm out, out, out of memory, like, I get to scan to every last, you know,
object and really count them all.
And that takes a really long time and can cause your program to pause for seconds or
minutes depending, right, on the amount of memory you're using.
Yeah, and that's why sometimes in Java you'll get get uh like i think it's out of heap space like a heap like a memory exception called out of
heap space and that means that you just don't have enough memory to do whatever you're trying to do
like you're allocating too much but there's another exception that you'll get i can't remember the
name but it's i think it's just something really generic like heap exception or heap run exception
what that means is you know you know you're right on the edge of how much memory you're using.
And Java, the garbage collector, is spending so much time doing all these really expensive, deep algorithms to clean out objects.
It doesn't have enough time to run your actual program.
And so you'll actually get either of these now, but basically most of the
time the solution is to give yourself more memory. Yeah. So, I mean, this is an interesting feature
of Java. This is the first time I remember this really coming into controversy because, you know,
early on, this is a big deal. Like if your program had to sit there and garbage collect, you could
really, you know, toast. Like if you think about if you're trying to write a game, you have to,
one, if you're going to run it at 30 frames
a second or 60 frames a second,
every 1 60th of a second, you have
to draw something on the screen or else people
see it as a stutter. And if Java
decides to go garbage collect at a bad time
and make you skip a couple
frames, you're going to get a stutter and people are going to not
like your game as much.
Yep.
Java also has interfaces.
So one thing that you have in C++ that you don't in Java
is multiple inheritance.
So in C++, you can have three different classes,
and one class inherit from all those classes
and get all of the functions and all of the data
objects and everything.
And Java said, we're not going to allow that,
because that causes a lot of problems.
Yeah, so the biggest problem with multiple inheritance is what's called the diamond
problem have you heard of this uh i probably know it by a different name so why don't you explain it
so yeah i'm going to do my best this is going to be tough but so basically the diamond problem is
when um you have so because of multiple inheritance you have two things that you're inheriting both
of those have a common parent and they both override some method foo of that parent and then
you call super dot foo like which one should it call that's the issue so to try and give an example
which is gonna be really hard but let's say let's say you have a game object which is
this is your player
in some game right
and game object inherits from
like physics object because your
player has some physics he jumps and his
velocity changes and things like that
game object also inherits from
let's say
like player or player object also inherits from entity, which entity is like
includes players and enemies and has things like hit points and like animations and things like
that. So you have you have your player object, it inherits from, you know, entity and from physics
object, and entity and physics object
they both inherit from drawable so
there's so a physics object can be drawn
and an entity can be drawn and so now
your player object calls you know parent
draw or just calls the draw function
well like which one should it call you
know because the physics object has a
way of drawing and the physics object has a way of drawing,
and the entity has a way of drawing the animations,
and you haven't really specified,
and the language doesn't really give you a way to say,
oh, from these two things I'm inheriting, pick this one, right?
Or even worse, someone outside of you calls the draw function, right?
Which one should it use?
So this is one of these fundamentally broken aspects of multiple inheritance there's pretty much no way to fix
it's a design thing you have to design it so you don't let this happen yeah you basically
yeah yes exactly right you just you cannot have that in your code so um if you have if you have
that situation you just have to hope that the things you're inheriting from that you have
access to that code and you can fix that so like if physics object was someone else's library like
the havoc physics engine and like you know the entity was part of like some like the source
engine from valve or whatever like you couldn't inherit from both of those at the same time
without causing the diamond problem so j Java gets around that by using interfaces.
And so the idea here with interfaces is you can only have one parent.
Like you can only have one way inheritance.
You can't have multiple inheritance.
But they understand that you might want to do, like the example I gave,
you might want to have an abstract the example I gave, you might want to have an abstract
physics object for all of your players and an abstract drawable object for all your players.
And you want the players to inherit both of those.
So Java adds this thing called interfaces.
And interfaces, they're not allowed to have any code in them.
And all of the methods have to be subsequently you have to be virtual but because of that they get around this diamond problem because you don't have any
there's no code to be ambiguous about yeah exactly so you know if you have 10 different interfaces
and then you have your parent and you call the draw function the draw function only exists in
one of those 11 objects, right?
Because the rest are all abstract.
So Java also has checked exceptions.
So C++ has later come to have exceptions and tries to have exception handling.
But Java really kind of did how the gate did it.
Like we're going to have exceptions and you can throw an exception in your code and then
code that's calling your code can check for that exception and handle it or allow the
person above you to handle it.
Yeah.
And kind of really do this as a way to say what happens when something goes wrong in
your program, which is important as a programmer.
And we can't keep going into deep on all of these, but we'll make you here for like four
hours.
Oh, yeah, it's true.
It doesn't mean to us.
But it really is important as a programmer to think about not just when things go right,
but what happens when things go wrong.
And I think too often as programmers, we forget to think about not just when things go right, but what happens when things go wrong. And I think too often as programmers,
we forget to think about that in advance.
We always just assume it's the happy, wonderful pony
and rainbow world, right?
Where everything magically works
and we don't spend enough time handling
what happens when things don't work.
Yep, and Java will actually force you to catch an exception.
Like in C++, you can always just not catch things
and it'll just cause your program to crash.
But in Java, it'll force you to do something about it.
You either have to catch it or you have to throw it against.
You have to say, I'm going to catch this thing,
or I'm telling the person above me that they have to catch it.
Yep.
The only way you can actually, it's not even really a crash,
but the only way you can halt your program
is by throwing the exception all the way up to main
and then throwing it through main.
And then you'll actually cause
your whole program to halt.
But in C++,
unless you do something special by default,
you're going to kill the program
with an exception.
So yeah, we should probably blow through
these strengths that we've missed this year
because we are...
So we talked about platform agnostic.
Java's got huge uh
community support there's lots of people what many big companies use java libraries and anything
you could want yeah example code support forums it's great yeah weakness it used to be speed
you know java used to be slow and that was probably fairly true in the early days
now it depends on what you're trying to do. It may or may not matter.
Yeah, I honestly have not seen it matter
in anything I've done recently.
But yeah, I actually wrote a graphics engine in Java way back
and speed was an issue back then.
But now it's just...
Yeah, and that's both because computers got faster
and also Java got more optimal, more optimized.
So hardware abstraction.
So Platform Agnostic was a pro.
Hardware abstraction, you don't have a lot of insight into what your hardware is really doing.
So it makes certain kinds of programs very difficult or impossible to write.
Yeah, and you can't, I mean, for example, you couldn't talk to the Kinect or something, right, in Java.
Unless somebody else wrote a library that interpreted that for you.
Right, exactly.
Which we can't get into how you do
that yeah let's let's get that but like yeah you'd have you'd have to write something in c
to talk to the connect and then talk to that in java basically yeah so the other weakness is uh
it forces you to be object oriented you know which is a strength but also weakness i mean it's not
doesn't let you be functional like in the case of C or C++, I can do function pointers. I could pass functions around. If I wanted something like MapReduce,
for example, I could pass a map function to MapReduce. And that kind of makes sense. It's
like, here's this, here's this pointer to this block of code. In the case of Java, if I want to
use like Hadoop or MapReduce or something like that, I have to create this map object
that doesn't have anything but a function in it.
And so it's not that big a deal,
but just knowing that you have to do things in an object-oriented way,
that could be a weakness.
And that's a limitation to certain people,
certain times it can be frustrating,
but of the language, not of the virtual machine.
Right. Because when we talk about, but of the language, not of the virtual machine. Right.
Because when we talk about other languages in the future,
other languages are purely functional and implemented on the same virtual machine that Java uses.
Yeah, totally.
Foreshadowing.
Yeah, exactly.
So I like Eclipse for editing my Java code.
Yeah, Eclipse is great.
If you use NetBeans, that's good too.
I used NetBeans for a few years.
Eclipse used to be – NetBeans used to be way superior to Eclipse is great. If you use NetBeans, that's good too. I used NetBeans for a few years. Eclipse used to be – NetBeans used to be way superior to Eclipse, you know, in like the early, like, 2000s.
But now I think Eclipse is almost universally better.
There's still some diehard NetBeans people out there, but they're both great tools.
You really just throw it down, man.
You just like lay it down.
This is better.
And then, like, you're just inviting the hate mail.
Yeah, I'm sure I'm going to get flamed for that.
But you know,
I think they're both great tools.
You can do great stuff.
And there's other ones,
many other ones as well.
You can always edit the eye.
Oh yeah, there's that too.
But yeah, there's even more IDEs.
Like what was that?
Bluebird or something.
I used BlueJ.
Okay.
Yeah, that was one that I used in college.
But yeah.
So Java is used for almost everything except for like applets.
Like I see applets now, but like kind of not a very great experience anymore.
But server side, Java is used heavily.
Yep.
So if you ever heard of Tomcat or Java server pages, JSPs or any of that, that's all Java.
Now that's different than another way that people write Java for the web, which is like
the Google Web Toolkit.
Right.
Or other such, which is you write Java code and run it through a compiler that generates
JavaScript for you.
Yep.
Yeah.
So that's pretty wild, right?
So you actually can do client side Java code using Google Web Toolkit.
And I've done a little bit of that.
It was OK.
I think.
DAN GALPIN- Yeah, I've never really done it.
But what I understand is that Google used that to do Gmail.
Right?
So early versions of Gmail or something were done this way.
Or to try to do stuff similarly is why they developed this and
kind of released it for other people to use.
Because it turned out they wanted to make the web a
better experience.
DAN GALPIN- Yeah, totally. And so that you can write Java code, which you're developed this and kind of released it for other people to use because it turned out they wanted to make the web a better experience.
Yeah, yeah, totally.
And so that you can write Java code which you're used to writing and it's kind of high
level but then it kind of spits out this JavaScript which may not be super readable for a human.
Oh, yeah.
But will work and your browser knows how to interpret it.
Yeah, totally.
We also talked about using it for Android.
Yep.
If you're doing Android, you're almost certainly writing Java.
Yep.
Jason mentioned Hadoop.
Yep.
Hadoop's all written in Java.
So for big data as well, which we haven't really talked a lot about big data.
Yeah, maybe we should do a show on big data.
That would be great.
Yeah.
That's awesome.
We should do that.
We're going to add that to the list.
The ever-growing list.
It's on the priority queue.
We got a couple of good, excellent reader.
No, listener feedback.
So we have some emails we need to respond to as well.
Some people have emailed us and said some nice comments,
giving us reviews on iTunes, showing us the love.
Yeah, yeah, thanks, guys, for doing that.
It's been awesome.
We're definitely going to keep the show going.
Yeah, we know we're not being as on the regular frequency as we're supposed to,
but we're really trying.
We really want to keep it going.
I think that, you know, we had a little bit of a
hiccup with sort of like, we got situated.
We have like a new recording studio.
Yeah. So that took a little
bit of like, you know, getting used to the move and
everything. But yeah, we should be
able to... We just got to settle back into the groove
and we should be back on a better schedule.
Yeah, totally, totally. So that's all I got, man.
Until next time. Yeah, have a good one.
This is an action-packed episode here. Talking fast at the end. Yeah, totally. So have a good one, guys, totally. So that's all I got, man. Until next time. Yeah, have a good one. This is an action-packed episode here.
Talking fast at the end.
Yeah, totally.
So have a good one, guys, and we'll see you in the next episode.
The intro music is Axo by Binar Pilot.
Programming Throwdown is distributed under a Creative Commons Attribution ShareAlike 2.0 license.
You're free to share copy distribute transmit the work to
remix adapt the work but you must provide attribution to Patrick and I and
share alike in kind
