Podcast Lookup

Java

Programming Throwdown

  • August 3, 2012
  • 1 h 18 min
  • Episode 17
Episode page
About this episodeThis show covers Java, a semi-compiled language used heavily in web and mobile development. News: Ouya android gaming console, Is C/C++…

This 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: Cygwin, MinGW and Macports, uShare.

★ Support this podcast on Patreon ★

Transcript

From the publisher

This transcript comes from the podcast’s own feed, shown as the publisher wrote it.

Java

00:00—
  1. A

    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

  2. B

    Week. So having a young daughter and talking to other people at work with young kids, we got into 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.

  3. A

    Yeah, well, I saw a one-year-old playing Angry Birds the other day. Were they doing it well? They weren't doing too bad. I mean, in other words, the bird was moving. They weren't getting a high score or anything, but 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 were kind of starting to get the whole, like, the bird doesn't go as far if you move your finger down.

  4. B

    Or whatever. Oh, wow.

  5. A

    They were doing the—I was impressed. I was shocked, actually. That's pretty good. Yeah.

  6. B

    It's a hard thing. So there's different classes. You can try to play, like, an educational-style game. 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

  7. A

    The blocks. Yeah, like the Cookie Monster one where you had to, like, add the cookies. Yeah.

  8. B

    And there's all these—you know, but those are kind of overtly educational, right? Like, obviously, this is—you're learning, you know, 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

  9. A

    Stuff. Yeah, yeah.

  10. B

    I mean, that's kind of interesting. I don't know how much a one-year-old

  11. A

    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 on the other end, next time you go in the middle or something. I mean, like, there's some core concepts there.

  12. B

    So I guess my debate was how soon—you know, not that it's a big deal, but, you know, 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.

  13. A

    Yeah.

  14. B

    That's true. So, 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 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 when I played, you know, Mario or whatever, I would get to the first level, second level, and then, you know, die, and there was no save games. And I would just play over and over again. It was really difficult.

  15. A

    Now I can play and, like, yay, I can get to level five before I die. No. So, of course, you know, my cousin thinks,

  16. B

    Like, oh, you know, Uncle Patrick's amazing at playing Mario. I'll have him beat this level for me. But then, you know, it's like they actually—it doesn't help them because they observe me play. But it's all, like, the subtle timing. So then every time they get stuck, instead of toughing it out themselves and learning,

  17. A

    they just want to

  18. B

    ask me, like, oh, hey, can you now beat—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 and me just keep beating these levels for you. Like, you know, you're not getting anything out of it. But, like, there was a long time before I was able to ever get a game to where I could beat it that wasn't a kid's game.

  19. A

    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 when 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. Yeah. Oh. Yeah. 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 Mega Man, like, you're playing to beat the game. You know what I mean? Like, when you're nine. Now when I play 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.

  20. B

    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. And I also don't have patience for that. Yeah.

  21. A

    So I'm comparing, like, myself, like, having not played for 20 years, playing for the first time, versus, like, myself at the end of, like, having played for six months straight. Right. Yeah. That's not

  22. B

    fair. Also, there is a thing out there on the internet. People talk about our games are becoming easier, right? So you have saves, then, you know, continuous save or walk away or, you know, you can just checkpoint, you know, way too often or have too many lives. Now, like, the common thing in first-person shooters is not to have to go collect help, but you get shot and, like, you just go hide behind a box for a few seconds and then you're, you know, help to charge back up or whatever. So, I mean, these things are making games easier. I always

  23. A

    feel like that was sort of, like, a cop-out because I think what that does is, like, 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, then we would spend more time on the harder levels, like, getting the important skills, you know? Yeah. So there's really, like, 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.

  24. B

    No, it's an interesting thing. So I didn't really have an amazing point there, but just I was thinking about this kids in games and whether my childhood playing games was good, too much, too little games, you know? What should it be now?

  25. A

    I wonder, like, are we going to be those parents that tell our kids to go play outside like our parents did, you know? I feel like you have to at

  26. B

    Some level. Like, you need to understand there's a world outside of games and computers and video. Like, 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, like, I feel like in order, it's such a part of society now and, you know, getting a job, especially if your child may show a, you know, 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.

  27. A

    If your child wants to listen to programming, throw it down, you

  28. B

    should let them.

  29. A

    That's a general rule that we've found. Yes, yes, yes.

  30. B

    So talking about games, 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.

  31. A

    OUYA! OUYA! This thing's pretty awesome. Basically, what they did is they took the Android OS and they created sort of an interface for the TV. So it runs Android, it connects up to your TV, I guess, 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 looks like it's going to have dual analog sticks and all that. And yeah, the idea is, you know, you can play all these Android games in a TV setting like and their whole like mantra is bring gaming back to the living room because the idea is, you know, I mean, we really, we haven't seen a new Xbox in a while. We haven't seen a new PlayStation. I think like 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 like casual games for your phone and things like that. So this is sort of an attempt to sort of create an open platform when something that's never really existed in the console world and bring gaming back to the living room. And it seems pretty cool.

  32. B

    Yeah. I like the idea of what they're trying to do. I wonder if they haven't bought a 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, I mean, the Wii 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 Wii 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 this Wii U 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 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.

  33. A

    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, 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

  34. B

    your friend's house.

  35. A

    Yeah, you're both playing together. Oh, interesting. I think

  36. B

    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, you know, football. And instead of having the plays up on the screen, you have to hide what button you're pushing.

  37. A

    Oh. Like you have it on your screen.

  38. B

    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 awesome. And you're making selection.

  39. A

    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. And 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 when you come home, you can like fight the battle that you've been like preparing for, you know, something like there's just so much potential. That's true.

  40. B

    Or like the immersive style games. They try to do this for a while where like you're at work and you, maybe it gets too much like Farmville, I guess. But, you know, something that 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.

  41. A

    Or maybe like your whole family is fighting the battle at the same time. So like you might be playing the game and like your wife might be like on her phone at work and she gets a notification like, I don't know, plays mini-game to help out. Maybe this is just

  42. B

    starting to sound like too much like work than

  43. A

    a game. I don't know.

  44. B

    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, right? And then requiring everything to have at least some free-to-play element, which is great. But, you know, I don't really want another closed place for games. Like I want a console that's like my PC, right?

  45. A

    And just download whatever I want. Yeah. Play whatever I want. If someone wants to make

  46. B

    an open-source version, great. You know, 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. Yeah. And I really hope

  47. A

    That's true. Well, 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.

  48. B

    Well, I think it's like it could be. 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.

  49. A

    Closely. Oh, I see.

  50. B

    To know. But like, what if you just wanted to release, like, hey, here's this crazy thing called Trivipedia? And

  51. A

    I want to release

  52. B

    it for you. And you just want to sell it.

  53. A

    You know, I don't want to sell it. Put a name to

  54. B

    it or something. Yeah. Like, will that be okay? And they've said, oh, will that be rootable? Then the issue is always, once you root it, there's problems with subverting the purchasing mechanisms in the store. So then they try to probably not let you be in the store if you haven't rooted. I don't know. We'll see. It'll be interesting. So I haven't backed it. Have you?

  55. A

    No, not yet. No? One thing, 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.

  56. B

    So the controllers have a touchscreen on them, like a touch-sensitive mouth pad thing. Yeah, yeah, yeah.

  57. A

    See, how come they don't have any? So if you look there in the middle

  58. B

    between the joysticks or whatever, between the analog sticks,

  59. A

    there's like a

  60. B

    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? 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? Yeah. $100. I mean, this is way lower than any other, you know, I mean, Microsoft. Yeah, that's pretty

  61. A

    sophisticated. Xbox, I guess, is like $140 maybe or $200 on the low end or something like that.

  62. B

    I mean, it's up there. And that's, like, they've sold, you know, loads and loads and huge economies of scale to get down to that price. So it'll be interesting to see what Ouya 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, it 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, that's right. 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?

  63. A

    Yeah, exactly. Yeah, it makes sense. Yeah, it's, you really have to get that critical mass to get the developers online and everything.

  64. B

    Yeah, but they, I mean, they've raised a ton of money, like $5 million, right? Yeah, it's insane. $5.4

  65. A

    million. You and I need to come up with a video game console. So we need to make this app for this console.

  66. B

    There you go, a game for the Ouya.

  67. A

    Yeah, yeah, the, you know, you have to do something all day game. Oh, the one we're talking about. Yeah, maybe we

  68. B

    will. All right. In all that

  69. A

    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. So, 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, you know, layout. So the example that the article gave is, you know, they went through, 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, like, 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, you know, working within that model. And so that, I feel like the article is sort of, you know, wasn't very holistic. But it's still a really interesting read. It's cool that Java actually outperforms, like, C++ and many different, you know, in this test case and many different compilers and things like that. Yeah.

  70. B

    That's cool. You know, we'll talk a little bit more about Java performance in our section to come. But I always see these, and I kind of am always a little doubtful because you really need a whole benchmark suite of really orthogonal tests. Because, I mean, yeah, we can probably find any number of things at which any language is faster than any other language, right? Like, 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 then 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?

  71. A

    Yeah,

  72. B

    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.

  73. A

    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? I mean, you know, worst case, let's say Java is 2 or 4x slower. You know, for almost any application, that would be fine. And, you know, a lot of times you hear people say, oh, I can't use Java. It's too slow. Or, you know, I have to do this in C. And that doesn't really—almost, 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. It's

  74. B

    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, like, you know, very well-written, 'Oh, actually, if you wanted this suits Java better, to suit C++ better, you would do it like this.' And, you know, 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. And, you know, what is it? Donald Knuth's quote in The Art of Programming, right, that early optimization is the root of all evil.' Yeah. I'm summarizing: premature optimization. There we go. Okay.

  75. A

    I found out—sorry to interject—I found out Donald Knuth and I go to the same optometrist. What?

  76. B

    Yeah. Can I switch optometrists? You could totally go to this optometrist. Can you, like, ask for an appointment that's, you know, like, you have to have your eyes dilated and you have to wait in the waiting room for a while? Can, like, ask for my appointment waiting to be, like, right when he's getting his eyes dilated so that I can talk to him?

  77. A

    You could, except now these guys are on this—what is it, Optiplex or something?—the thing where they take, like, that image of your eye. Oh, man. Yes, you can't do that. 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

  78. B

    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 optometrist.

  79. A

    He's a pretty cool guy, too. Okay, I'll

  80. B

    have to give that from you later. Yeah. 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

  81. A

    of it.

  82. B

    And wrapped parts. So I think it's interesting. Now, as far as what they managed to accomplish, did they create life? You know, well, I mean, they used some existing cells, so no. And also is 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, you know, balloon and squeeze out the water to move forward. Which isn't efficient. It isn't, you know, 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.

  83. A

    a way that really resembles things.

  84. B

    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,

  85. A

    Really? And so, like, they thought

  86. B

    it was able to lead it

  87. A

    At one point. Wow, that's awesome.

  88. B

    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 know, 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. And even today, we're kind of, people will look back on this jellyfish and say the same kind, well, maybe not this jellyfish, but these kinds of endeavors, right? And

  89. A

    kind of say

  90. B

    the same thing. Oh, these people are trying to.

  91. A

    Yeah, I think that, like, if 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 way better than a supercomputer, right? And so all of these attempts to sort of, like, integrate, you know, what we know of computing and processing with, you know, the animal world and sort of how the brain works 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

  92. B

    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. Yeah. And people insert brain inserts, right? I mean, all these kinds of things are so cool. It's, you know, being able to bring stuff that much closer. You know, originally computers were in a giant room and it couldn't go with you. Then now everybody carries around very powerful computers in their pocket. And then, you know, maybe soon, you know, on their glasses, you know. 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.

  93. A

    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 basically that it would pass the Turing test 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. Yeah. And 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 muscles are just a bunch of thin fibers that are put together. But yet a robot has just a single joint. Like a motor, yeah. Yeah. And so, like, why isn't a robot knee more like a human knee where it's 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 they're all, you know, maybe this jellyfish, you know, makeup is a step in that direction, right?

  94. B

    Yeah. I mean, that is true. Even if you had really good AI today, I mean, we still don't have, we don't have, like, a vessel to put it in that would allow it to really act like a human. It

  95. A

    Would be obvious. Yeah, exactly. Like,

  96. B

    They don't move. They're not capable of bipedal robots of today. They 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 run mobile devices. The growth just don't match. And I wonder if it will 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. In other words, everybody can't go into computer science.

  97. A

    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, 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 GNU packages that people have made and bring those over into other operating systems. So, Cygwin, 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 that they made this, is actually what's called POSIX. So, a little bit of history. Unix runs on top of 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 call fork, 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. You know, the functions just do what they're supposed to. And to these higher level programs, it just works. Which is a beauty of

  98. B

    Something like POSIX.

  99. A

    If you kind

  100. B

    Of really restrict, here's, in essence, kind of an API you're programming against. Yeah. How strong that can really be.

  101. A

    Yeah, totally. So, Cygwin is awesome. And there is one problem with Cygwin, which is, you know, you have this POSIX code. And it's wrapped in what's called the Cygwin1.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, that 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, you know, 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.

  102. B

    The other issue that I've run into before with Cygwin1 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 is normally, it takes, you know, 10 milliseconds in Linux, but it might, because of all the extra work that has to be done in Windows to simulate, it might take 10 seconds or something crazy. You can end up with programs that are just completely unusable or, you know, just take a really long time. Because, like, for instance, Fork in Linux is a completely different kind of operation than creating a new process in Windows.

  103. A

    Yeah, you're totally right. So, in general, so let me get to the alternative Cygwin, 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 know, I write my code, I have access to all these cool POSIX functions, but then what they do is at compile time, they dump it all together into an executable that completely is self-sufficient. So, you don't need the Cygwin DLL. It's not, MinGW isn't GPL, so you're not, like, you're okay there. And, in general, the executables are faster. So, the bad thing about MinGW is it doesn't have this package manager. Like, with Cygwin, you could just run the Cygwin package manager and say, I want GTK, and it'll do everything. You have a couple of clicks, and now you have GTK. MinGW is more of a compiler, so it's not really meant for that kind of thing. So, in general, you know, use Cygwin when you want to run Unix programs, and use MinGW when you want to make programs from the Unix libraries.

  104. B

    Yeah, that are kind of comparable. That's the way I kind of use it.

  105. A

    Yeah. So, yeah, that's for Windows. Now, for Mac people, don't feel left out. You can totally use, you know, 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, geez, how Would you describe MacPorts?

  106. B

    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.

  107. A

    Yeah, that's right. Whereas OS

  108. B

    X kind of is. So, OS X 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.

  109. A

    No, I think that's right.

  110. B

    But to get at the understanding that underlies, like, here's how to do the thing you would do in Linux, but on OS X. Yeah, I

  111. A

    think that's exactly right. So, MacPorts 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, like, 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. Yeah, I guess the other

  112. B

    thing is, yeah, making sure that the right libraries are there. Yeah. Because it doesn't, you know, it doesn't natively know how—you know, 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.'

  113. A

    Yeah, exactly. Yeah. So, yeah, these are great. If you use Windows, you should definitely—you should be using Cygwin. 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, you know, because there could be, like, some really interesting tools that you've never heard of or maybe new programming languages that you want to try—that, you know, are already there that you just have a couple of clicks and you can get them on your computer.

  114. B

    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, I think. Oh, really? So, I think OSX has BSD underneath it. Oh, okay. And even then there's some other swirly stuff. So, please just, like, anything that

  115. A

    was said in the last, it wasn't quite right; just please forgive

  116. B

    Us or forgive me anyways.

  117. A

    Wow, that's our first mistake ever. Man, it's like a milestone mistake, number one.

  118. B

    Yeah, yeah, number one. Yeah. So my tool of the bi-week is far less technical than that. You share. And I have a Google TV, a Logitech receiver at home. And I had some file, some movie files on my computer. And I wanted to stream from one to the other because 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 have, 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, like, an Apple TV. Yeah. 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 seem 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.

  119. A

    Nice. So that

  120. B

    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

  121. A

    an actor name: Tom Hanks.

  122. B

    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

  123. A

    Data. That sounds cool, though.

  124. B

    That would be cool if it worked. Oh, okay. And then if it doesn't work, it kind of, like, seems like most of them just default into kind of, like, giving up or whatever. And, you know, it was like a mess. So I just wanted, like, I have it fairly well structured in a file folder structure that I wanted. And Ushare 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, you know, only does a very limited set of codecs, 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 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

  125. A

    from me that you share. Nice. And we have a link in the show notes. So just so I wanted to, because my media setup thing is a disaster. I need you to come over. I need to hire you as a consultant. That sounds like a time sink. But so I have a desktop which has a bunch of movies on it 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 an NFS, but it doesn't quite work right because it's not a true media server. So, like, there's all sorts of latency and sometimes the 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?

  126. B

    So on the laptop, you know, there's all sorts of what you want is a UPnP or a DLNA client, right?

  127. A

    So there's, like, all sorts.

  128. B

    It's like I think VLC will even do this, right, 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 share, will do this too. It will 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

  129. A

    Reliably across the network. This is amazing.

  130. B

    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. And so I kind of ended up taking the shotgun approach and installing like five different UPnP servers and seeing which one would just work nice with my device.

  131. A

    And then you use VLC as the client?

  132. B

    So on mine, I have a Google TV.

  133. A

    So Google TV

  134. B

    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 programs you go run and select the file you want to play. And then it'll 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. Yeah,

  135. A

    I think it is.

  136. B

    Whatever the Windows Movie Player thing is. Yeah. You know, or like I said, I think VLC will do it. There's also Xbox Media Center, which we talked about last week,

  137. A

    is a UPnP

  138. B

    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

  139. A

    remote. Oh, that is totally cool.

  140. B

    And then be able to play it that way.

  141. A

    Nice. That is awesome. I'll have to check that out.

  142. B

    So if it works,

  143. A

    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,

  144. B

    Oh, it's not working. What happened?

  145. A

    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.

  146. B

    Anyway, check it out. That should you share.

  147. A

    Yeah, it looks awesome. Yeah, I'll definitely do that. And 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.

  148. B

    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

  149. A

    some more of these things later.

  150. B

    So Java kind of has an interesting history. I mean, everything has an interesting history, I guess, if history is interesting to you.

  151. A

    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. Yeah.

  152. B

    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 was 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.

  153. A

    Yeah, yeah, that's right. The hotness. So their slogan, which I think, you know, is

  154. B

    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. Yeah. 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 out, like, 2012, and you say, like, hey, Java, where is it running? And Java runs on all sorts of platforms and devices. And, you know, I don't know how much the write once part comes into there. But they really are, you know, making it so that it is so much more pervasive than a lot of other languages ever reach.

  155. A

    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 Endian, Little Endian. 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. Like, God forbid you try to, like, you know, memcpy 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, a virtual machine, like VirtualBox or something that runs a completely bare-bones Windows and run your program there to 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 IDEs, 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

  156. B

    look it up.

  157. A

    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, like, extremely high. He can just double-click the file you gave him and it'll work, you know? And you're just bypassing all of the things that I mentioned before. So, I mean, this is huge, you know? Now we take it for granted. By the time, this was just incredible that you could do something like this.

  158. B

    Yeah, I feel like there's a lot of legacy that goes into Java. So, you know, and whenever we talk about it, ultimately you kind of talk about it from one aspect. There's, like, the individual programmer. There's, like, the enterprise team. There's the, you know, person learning to program. There's all these different things. And so, you know, kind of have to take one view at a time. But, you know, 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.

  159. A

    Yeah, a good point. And we

  160. B

    talk about that a lot on this, you know, 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 a line for a line. Just, like, copy it into Java. Well, you can't expect that it's going to be, like, the greatest ever. Because, you know, that's not, you're not using it the way it's meant to be used.

  161. A

    Yeah, totally.

  162. B

    So, and then, you know, one really cool feature of Java was this notion of applets. So, Java in 1995, it's coming out, you know. And this is, like, right around the time, or at least I remember, like, the internet was really coming into, like, 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.

  163. A

    Yeah, I mean, and this was 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. Blink 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 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 screen if I want on someone's website. And that just, like, blew people's minds. One of the most popular applets, remember, 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, a tool. Oh, I don't think

  164. B

    I've never seen this.

  165. A

    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

  166. B

    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 and had these applets, and 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 only 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

  167. A

    know, one interesting side note: SGI did Silicon Graphics Incorporated, did a bunch of crazy pioneering graphics research. Like, when the Nintendo 64 came out, 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 3D rendering, and it was totally kind of crazy off the wall. And then they tried that. They refined it. Then they switched to the polygon model. They did all this pioneering research, and then they died, you know, and it's sort of like this huge investment, and the company dies 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, you know? Like, it's kind of like... Well, it

  168. B

    wasn't exactly immediately. I mean, it... Yeah,

  169. A

    When did they get bought? I looked it up. It was

  170. B

    fairly recently, right? So, I mean, I think they had a good, like, 10 years, 15 years or something.

  171. A

    Oh, is it really that long? Yeah.

  172. B

    And Sun did a lot of other stuff as well, right? Like, I don't know. 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 made... They used to make like server hardware and stuff as well. Well, yeah,

  173. A

    I guess... Was

  174. B

    that before or after Java? I

  175. A

    don't. Well, yeah, Solaris has been out forever, right? So, yeah. 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 why that is.

  176. B

    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.

  177. A

    Yeah, that's a good point.

  178. B

    So, that can happen. But, yeah, so, I mean, Java really... 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's going to do it, and Java's 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, you know, 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. Yeah. And it's kind of amazing that Java was able to do that as well as it did.

  179. A

    Yeah, totally. And the cool thing about Java is they kept it very close to C++ from a syntactic point of view, but they... So people... So it was like... You could think of it as, like, 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++ was 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... 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++, it's like, that stuff's a disaster, right? Like, try and do that as just a nightmare. Like, bang your head against the wall. And it's because it's sort of... You know, C++ was, like, sort of trying to do the whole classes thing, but still, like, interact, like, completely transparently with C. And so by Java sort of separating itself from all that and saying, you know, we're not going to have these, like, native arrays and all these things and, you know, just functions hanging out, like, you know, global functions. We're not going to do that. But by making these, like, restrictions and by making a brand-new language, they're sort of able to make it a lot cleaner.

  180. B

    Java also sticks out in my mind as coming out with updates. So I guess because, like, C++ was kind of written and it wasn't really a company that kind of owned it, right? Like, this is our thing. We're making it. It was good and bad. So Java came out. Sun owned it. They, you know, 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, Chase was talking about, 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.

  181. A

    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.

  182. B

    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, like, a Java code written today against, like, an early Java, I don't think it'll work.

  183. A

    Yeah. So much stuff

  184. B

    has changed. And just even, like, 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 they, I feel like they were able to do that because they could. Yeah. Because they kind of, you know, owned the stack in a way. But that didn't stop. I mean, they, 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, I mean, even from early, 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. Yeah. I

  185. A

    saw something interesting the other day where someone wrote an LLVM, like, interpreter for bytecode or something like that. Actually, it was, no, it took in bytecode and it outputs C code. Oh. It's like this Java to C, C, like, compiler. It was kind of crazy.

  186. B

    So, but, I mean, yeah, the bytecode is essentially machine code, assembly code for a, like, known virtual machine that isn't a real PC. Yeah. 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. Yeah. And, you know, again, ignoring all of the licensing and problems and copyright, but, I mean, 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, Android program on an Android phone, that seems redundant. 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.

  187. A

    Yeah, exactly. And

  188. B

    They're able to, you know, 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, they—and 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, 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.

  189. A

    You know, Oracle.

  190. B

    But 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. Yeah, I guess that speaks to, like, the flexibility. It hasn't fallen by the wayside.

  191. A

    Yep, and I think that, you know, a lot of the research in, like, just—so one thing Java has, and, you know, 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

  192. B

    executing the already semi-compiled version of your code.

  193. A

    Right, yeah. The

  194. B

    version in Java assembly.

  195. A

    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, like, 30 instructions are guaranteed to run. Let's say the next thousand instructions before you get to an if or a branch. So, let's, let's see if we can do something clever. Like, maybe these 30 instructions are all adds 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, like, really clever things and do that at runtime. Yeah. Based on

  196. B

    the hardware it's running on. Yeah,

  197. A

    exactly. And do it, like, right a little bit ahead of, like, just in time. Just a little bit ahead of, you know, 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, you know, interesting things. University students could go through and make all sorts of crazy optimizations and do a lot of experimenting. And Java's always been really synonymous with academia since the beginning. Yeah,

  198. B

    I mean, when I was in college, that's the—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.

  199. A

    Yeah, I was the same way. And even in operating systems, we still wrote

  200. B

    some Java for a lot of the multi-threading.

  201. A

    Example stuff. But

  202. B

    For like a lot of the very, very low level stuff, we had to write C, which was many people's first time ever using C. Yeah, that's a scary experience.

  203. A

    I remember the first time I saw in C somebody casted, like, he had a character array and he wanted to put a struct in the array because the character array was 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 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.

  204. B

    Yeah, I agree. It's kind of interesting to see because I learned C++ first and then did most of my learning in Java, like, at the university. But still, like, I came into it with thinking about things in terms of pointers and memory layout and, like, 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 it's 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, you know,

  205. A

    pointer indirection.

  206. B

    You know, 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 everything. But it's because I'm used to, like, I need to do it this way because else my C++ program is going to blow up.

  207. A

    Yeah, exactly.

  208. B

    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'll 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.

  209. A

    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 with Java, it sort of forces you to follow a certain structure. And even if the structure, you know, 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, right? But still, to write it in Java and follow, like, 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?

  210. B

    Except Perl. You'll always make a mess.

  211. A

    If you're writing Perl.

  212. B

    Yeah. 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++ will force you into 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. And it's kind of like, you know, growing up in school, you always told you you got to write your outline before you write your paper. And I feel like I always did terrible at that. Like, I always just wrote the paper and then wrote my outline based.

  213. A

    on what the

  214. B

    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.

  215. A

    Yeah, totally. So,

  216. B

    some of the features that Java has, you know, we talked about some of them already, but generics. So, what is the idea of a generic? That sounds like a really bland

  217. A

    topic. 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 had, 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, to make a list class, right? So, you don't want to have a list of integers. You want to have, like, my class intList, 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 doubleList and a floatList 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 E is. And then later on, you want to say, okay, I want a list of ints, I want a list of, you know, doubles, I want a list of floats. Or

  218. B

    custom classes, a

  219. A

    list of custom classes. 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 E is my template. Let's make a copy of this code, and everywhere I see E, I'm going to 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 actually works kind of differently. So, instead of being that sort of low level, it will actually, 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, like, this specific list, like, if you say, like, List, PatrickList, you know, PatrickList push, you know, 1. 0 or something like that. So, it knows that PatrickList is a double list and it's not an int 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 always, it's, like, universally better. But in Java, you know, in the case of generics, you are paying, like, a little bit of an overhead, you know, price there.

  220. B

    That was a good summary. It is one of those things that are, is subtle and 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. Yeah. How do I write code that applies to many different kinds of objects?

  221. A

    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 type, so you put int, float, whatever. And the second template parameter is literally a number. So, you can say, like, BoostArray, you know, this is in C++, you can say BoostArray and it'll 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. All right, that's generics. Why don't you

  222. B

    cover garbage collection? So, so garbage collection in C++, if you—so there's 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?

  223. A

    I like to think of colorful examples.

  224. B

    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, you know, I don't know if your backyard can be considered a forest. But

  225. A

    anyways, you want

  226. B

    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, you know, 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 need. But then dynamically, you need to be able to say, I'm going to have a hundred tree heights, I'm going to have five tree heights, I'm going to have a thousand 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, I do that with the new, and what it does is instead of where static memory comes from one place, 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, like it's all in a row, but it's just—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 system's 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 maybe 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 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. Yep. 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 no longer need these variables as 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—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.

  227. A

    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 do you not need anymore?' And that's an expensive process. Yeah, and so there are great amounts of

  228. B

    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.

  229. A

    Yeah, and that's why sometimes in Java you'll get, 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 'HeapException' or 'HeapRunException.' 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, like, really expensive, like, deep algorithms to, like, you know, clean out objects that, like, it doesn't have enough time to run your actual program. And so, and so you'll actually get either of these now, but basically, most of the time, the solution is to give yourself more memory.

  230. B

    Yeah, so, I mean, this is an interesting feature of Java. It was 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—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. 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.

  231. A

    Yep, yep. So,

  232. B

    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.

  233. A

    Yeah, so the biggest problem with multiple inheritance is what's called the diamond problem. Have you heard of this?

  234. B

    I probably know it by a different name, so why?

  235. A

    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 you have, 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 going to be really hard, but let's say, let's say you have a GameObject which is this is your like, your player in some game, right? And GameObject inherits from like PhysicsObject because your player has some physics. He jumps and his velocity changes and things like that. GameObject also inherits from, let's say, like Player, or PlayerObject 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 PlayerObject that inherits from, you know, Entity and from PhysicsObject, and Entity and PhysicsObject because they both inherit from Drawable. So, there's so a PhysicsObject can be drawn and an Entity can be drawn, and so now your PlayerObject calls, you know, parent draw or just calls the Draw function. Well, like which one should it call? You know, because the PhysicsObject 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 this is one of these like fundamentally broken aspects of multiple inheritance. There's pretty much no way to fix.

  236. B

    Wait, it's a design thing. You have to design it so you don't let this happen.

  237. A

    Yeah, you basically, yeah, yes, exactly right. You just you cannot have that in your code. So, 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 PhysicsObject was someone else's library, like the Havok 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, 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 know, you might want to do, like the example I gave, you might want to have, you know, like an abstract PhysicsObject for all of your players and an abstract DrawableObject for all your players and you want the players to inherit both of those. So, Java adds this thing called interfaces. Interfaces. And interfaces have they're not allowed to have any code in them and all of the methods have to be subsequently have to be virtual. But because of that, they get around this diamond problem because you don't have any... There's

  238. B

    no code to be ambiguous about.

  239. A

    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.

  240. B

    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 that. 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 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.

  241. A

    listening to

  242. B

    us. 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 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.

  243. A

    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.

  244. B

    You either have to catch it or you have to throw it again so you have

  245. A

    to say I'm

  246. B

    going to catch this thing or I'm telling the person above me that they have to catch it.

  247. A

    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 this year because we are. So we talked

  248. B

    about platform-agnostic Java's got huge community support. There's lots of people, many big companies

  249. A

    use Java. Tons of libraries and anything you could want. Yeah, example

  250. B

    code support forums. It's great. Weakness: it used to be speed. 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.

  251. A

    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

  252. B

    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.

  253. A

    And you can't—I mean, for example, you couldn't talk to the connect or something right in Java unless

  254. B

    Somebody else wrote a library that interpreted that for you, right?

  255. A

    Exactly, which we can't get into. How you do that? Yeah, let's skip that. But yeah, 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 it forces you to be object-oriented, you know, which is a strength but also a weakness. I mean, it's not—it 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 like this Map object that has just like doesn't have anything but a function in it. And so it's sort of not that big a deal, but just knowing that like you have to do things in an object-oriented way—that could be a weakness. And

  256. B

    That's a limitation to certain people, certain times. It can be frustrating, but of the language, not of the virtual machine, right?

  257. A

    Because when we

  258. B

    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

  259. A

    I like Eclipse for editing my Java code. Yeah, Eclipse is great. If you use NetBeans, that's good too. I've 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

  260. B

    just throw it down, man. You just like lay it down. This is better. And

  261. A

    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

  262. B

    many other ones as well. You

  263. A

    can always edit the—Oh yeah, there's that too, but there's even more IDEs like what was that? Bluebird or something? I use BlueJ. Okay. Yeah, that was one that I used in college, but so Java is used for almost everything except for like applets. Like I see—like I see applets.

  264. B

    now, but like kind of not a very great experience anymore. Yeah

  265. A

    but server side. Server

  266. B

    Side Java is used heavily.

  267. A

    Yep. So if you ever heard of Tomcat or Java Server Pages (JSPs) or any of that, that's all Java now.

  268. B

    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.

  269. A

    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 okay. Yeah, I've never really done it, but...

  270. B

    What I understand is that Google used that to do like Gmail, right? So like 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. Yeah, 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.

  271. A

    Yeah, totally. We...

  272. B

    Also talked about using it for...

  273. A

    Android. Yep. If you're doing Android, you're almost certainly writing Java. Yep.

  274. B

    Jason mentioned Hadoop. Yep. Hadoop's all Big Data as well, which we've never really talked a lot about. Big Data. Yeah.

  275. A

    Maybe we should do a show on Big Data. That would be great. Like, yeah, that's awesome. We should do that. We're going to add that to the list.

  276. B

    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.

  277. A

    Yeah, yeah. Thanks guys for doing that. It's been awesome. We're definitely going to keep the show going. Yeah, we...

  278. B

    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.

  279. A

    It going. Yeah, 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.

  280. B

    Back into the groove, and we should be back on a better schedule. Yeah.

  281. A

    Totally, totally. So that's all.

  282. B

    I got man. Until next time.

  283. A

    Yeah, have a good one. Here. Talking fast at the end. Yeah, totally. So have a good one guys, and we'll see you in the next episode. The.

  284. B

    Intro music is Axo by Bynar Pilot.

  285. A

    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 and adapt the work, but you must provide an attribution to Patrick and I, and ShareAlike in kind.