From the textbook that thought there was a java.io.OutputStreamReader



  • "Using design patterns like Command makes your code shorter, easier to read, and easier to maintain!"

    They then go on to design a "maze game" which has the following structure:

    • Maze contains an ArrayList which contains Room objects. No, not a List<Room>, an ArrayList.
    • The list is never used.
    • Each Room contains four MapSite objects. MapSite is an interface implemented by Room, Door, and Wall. Room is never used in any context that Wall or Door is used.
    • Doors can be open or closed. Forever. There is no way to open or close a door. Closed doors are functionally equivalent to walls.
    • The game has a command line argument to change the graphics to use "Harry Portter" or "Snow White"-themed mazes. If you want a maze that just uses shades of gray, you need to specify "Default" as a parameter or the program will exit without displaying a window.
    • They implement different graphics by using the factory pattern. An interface named MazeFactory has the methods makeMaze, makeRoom, makeWall, and makeDoor. There is another interface named MazeGameFactory that has the createMaze function, which makes a maze.
    • Apparently the best way to implement different images is to subclass each thing that is displayed for each possible image.
    • The ability to undo "move" commands is implemented, but there is no keyboard shortcut for undoing movement and the mouse is not used.

    Walking is done by pushing arrow keys. Here is how they do it:

    // nested inside maze.Maze
    static class MazeKeyListener extends KeyAdapter {
        MazeKeyListener(Maze maze) {
            this.maze = maze;
        }
    
        public void keyPressed(KeyEvent e) {
            System.out.println("Key pressed");
            Command command = null;
            int code = e.getKeyCode();
            switch (code) {
            case KeyEvent.VK_UP:
                command = new MazeMoveCommand(maze, Direction.NORTH);
                break;
            case KeyEvent.VK_DOWN:
                command = new MazeMoveCommand(maze, Direction.SOUTH);
                maze.move(Direction.SOUTH);
                break;
            case KeyEvent.VK_LEFT:
                command = new MazeMoveCommand(maze, Direction.WEST);
                break;
            case KeyEvent.VK_RIGHT:
                command = new MazeMoveCommand(maze, Direction.EAST);
                break;
            }
            if (command != null) {
                maze.doCommand(command);
            }
        }
    
        Maze maze;
    }
    

    And here's the doCommand method:

    protected void doCommand(Command command) {
        if (command != null) {
            moves.push(command);
            command.execute();
        }
    }
    

  • SockDev

    name and shame.

    please?





  • Crazy Bob's Discount Textbook Emporium!


  • I survived the hour long Uno hand

    My worst Java textbook was Objects First. Fuck Objects First.


  • BINNED

    I love it how much Java is still used as a beginner language.

    People complained how it's stupid to teach C as a first language because (among other reasons), when you're just starting you're just taught to use #include <stdio.h> int main(void) { ... as a mantra without any understanding. Because public static class main is sooo much simpler to understand.

    As much as I might not be a fan, use python damn it! Or LUA. Hell, C is not as horrible to start with as Java is.

    Disclaimer: no idea if the book in the OP is for beginners. I just needed to vent somewhere.



  • @Onyx said:

    public static class main

    Your Java teachers were the worst of the worst.



  • public static final default abstract strictfp void main(String[] args);
    


  • @Onyx said:

    Hell, C is not as horrible to start with as Java is.
    I disagree here; in fact, for 90% of people I think you'd have a hard time coming up with a language that I think is worse than C to start with, save for languages like Brainfuck that are made as a joke and maybe something like APL or COBOL. FORTRAN is maybe the only contender that I can semi-realistically see being used somewhere.

    I'm not exactly a fan of Java as a first language, but my argument against C is that there is a metric fuckton of stuff that you have to deal with that is distracting from the main thing that is hard about programming, which is breaking down a problem into little bits that you can describe exactly in a formal language. Debugging with memory errors doesn't help you learn that. Having a language where anything dealing with strings is about as fun as stabbing yourself with a fork a bunch of times doesn't help you learn that.


  • BINNED

    @Keith said:

    Your Java teachers were the worst of the worst.

    It was some kind of a tutorial, and possibly my faulty memory. Even without the class keyword, you can't avoid explaining public without first explaining concepts of OOP.


  • BINNED

    @EvanED said:

    Debugging with memory errors doesn't help you learn that.

    Meh. One crashes, one throws NULL pointer exceptions. Neither work due to a memory error. They just display different symptoms.

    @EvanED said:

    Having a language where anything dealing with strings is about as fun as stabbing yourself with a fork a bunch of times doesn't help you learn that.

    True. If you went with a C-family language I'd start with C++ at least, so you can use std::string and all the stl stuff. And you don't have to go into the OOP right away, you can write the same thing as you would in C with slightly less hassle at least.

    As I said, I'd still rather go with Pyhton or Lua for beginners.



  • @Onyx said:

    It was some kind of a tutorial, and possibly my faulty memory. Even without the class keyword, you can't avoid explaining public without first explaining concepts of OOP.

    Agreed. When I was first introduced to Java, we were shown public static void main with the promise that it would be explained later. It's definitely not ideal, but Java isn't a bad language to teach people.



  • @Onyx said:

    Meh. One crashes, one throws NULL pointer exceptions. Neither work due to a memory error. They just display different symptoms.

    One throws NULL pointer exceptions in a deterministic, guaranteed manner. The other corrupts some random piece of data, runs for another five minutes, then gives you a wrong answer miles away from the source of the actual problem.


  • BINNED

    void! That's what it was! I knew it was something that made me say "every single word here is wrong!"



  • So, I've participated in several CoderDojos for kids and I have some experience with teaching kids different languages:

    Python

    It's so different from anything else out there that kids have a very hard time when moving to C like languages. Since we were doing some web stuff, they had a very hard time learning JavaScript later on. Python is not object oriented and is very hard to explain this concept with Python. Also, you don't want to abstract them from types at this early stage.

    JavaScript

    So easy to start and have the computer (the browser actually) do something, that kids have a great time with it. Then you have all the games and stuff around and JavaScript is great for introducing them. Now, spaghetti code at its best. Also, very hard to explain types and stuff like:

    2 === "2" 
    true
    2 == "2"
    false
    

    Java

    We did some Minecraft mods using Java and kids were learning about OOP without realizing this. Hard part is that we had to set up their systems. On the other hand, they later had much an easier way of differentiating what a class, an instance, a method and a variable are. Also, when you explained them dynamic variables, they understood them better since they already knew what was going on there.



  • @Eldelshell said:

    2 === "2"
    true
    2 == "2"
    false

    Say what now?



  • @Eldelshell said:

    Python is not object oriented and is very hard to explain this concept with Python

    Eh? It's multi-paradigm and certainly supports OOP. Sure, you don't have to encapsulate everything in a class but it's perfectly adequate for introducing OO concepts.



  • I'm not going into a flamewar about this, but OO in Python is an add-on to a scripting language. I mean:

     def __init__(self, name)
    

    That's a scripting language trying to be object oriented.

    And don't get me wrong, I love Python since version 1, but it's not an introduction language for OOP concepts.



  • @Eldelshell said:

    2 === "2"
    true
    2 == "2"
    false

    Copy-pasta'd from my chrome developer console:

    2 === "2" false 2 == "2" true

    But I do know javascript has some oddities in comparison operations (I can't remember them offhand).

    My recommendation to clean things up a bit would be to use jslint. It suggests style standardisations and helps catch some errors and superfluous code.



  • Basically, == does type conversion where === doesn't.



  • @Yamikuronue said:

    My worst Java textbook was Objects First. Fuck Objects First.

    You are objectifying women!



  • @Eldelshell said:

    Basically, == does type conversion where === doesn't.

    Type conversion? Like undefined == null, and 0 == "0" == false, and the other combinations are not? What type conversion is that? Why not undefined == 0 or null == 0? And if it's type conversion, why are !false and !0 true, but is !"0" false and are !undefined and !null true? Even !0.0 is true. That's some absurd type conversion. It's just a weird convenience thingy that they hacked in the first hours, and now is introducing subtle bugs.



  • @Eldelshell said:

    That's a scripting language trying to be object oriented.

    And don't get me wrong, I love Python since version 1, but it's not an introduction language for OOP concepts.

    As to your point: Python, in many ways, has a more pervasive OO notion than even Java. Dig into the way the built-in file, function, and class types work, sometime if you want to see the pervasiveness first-hand...

    Also, why are you trying to introduce new programmers to OOP like it's some sort of programming gospel?! Are you trying to stunt the development of another generation of programmers with noun-fetishist brainworms?


  • SockDev

    @Yamikuronue said:

    My worst Java textbook was Objects First. Fuck Objects First.

    i'd say to do so with a giant purple dildo, but.... well that's an object too.



  • public static final default abstract void main(String... args);

    Added a character for you





  • @Onyx said:

    As much as I might not be a fan, use python damn it! Or LUA.

    At least C and Java have IDEs that are... barely acceptable.

    How about we teach our kids a good programming environment, then maybe they'd go back to those open source idiots (and Java incompetents) and demand to know why their shit isn't nearly as good as what Microsoft had a decade ago.



  • Back when I was learning, both meant you had to reboot because you were using a computer without protected memory.

    Kids these days! What with their preemptive this and protected that!



  • @Hanzo said:

    You are objectifying women objects!

    FTFY.



  • @Eldelshell said:

    Basically, == does type conversion where === doesn't.

    Kind of. Of course, it's not advisable to use javascript that way. It does provide people with a lot of rope to hang themselves with.



  • @mott555 said:

    You are objectifying womanising objects!

    FTFY.



  • @EvanED said:

    One throws NULL pointer exceptions in a deterministic, guaranteed manner. The other corrupts some random piece of data, runs for another five minutes, then gives you a wrong answer miles away from the source of the actual problem.

    O god, Eclipse based C IDEs always end up corrupting their project files and shitting up NULL pointer errors like no tommorrow. Fuck Java and null pointers but fuck idiots unable to handle it.


  • BINNED

    @blakeyrat said:

    At least C and Java have IDEs that are... barely acceptable.

    Interactive shells are the future man, get with the times!

    Filed under: 10 PRINT "Awesome!" 20 GOTO 10



  • I was unfortunate enough to begin with Java, and while I can't stand the way it is taught (SUBCLASS EVERYTHING!), the worst part was how hard it made learning C for my classmates.

    I'd be in favor of teaching programming basics in LOLCODE.



  • Misobjeny?



  • Everyone's first language should be QBasic.

    Also, Java is still TRWTF.



  • Why? It has been paying my bills for the past ten years.



  • @Hanzo said:

    0 == "0" == false

    I disagree. From my JS console:

    0 == "0" == false
    false
    

    @JazzyJosh said:

    public static final default abstract void main(String... args);

    Final abstract?


  • BINNED

    @chubertdev said:

    Everyone's first language should be QBasic.

    Personal anecdote:

    We started in LOGO (working on DOS computers without a hard drive... in late 90s...) and moved on to QBasic. I don't know if my teacher really didn't know jack about any programming beyond LOGO's REPEAT and FOR, or he was just lazy, but I had to figure out conditionals and loops in QBasic from the manual myself since I was interested in that stuff. He was genuinely stunned when I showed him a simple quiz game I cobbled together just reading the manual.

    Sigh... If only I had access to proper computers sooner, I might be able to read more of this forum without having to look stuff up by now. But thank you QBasic manual, you put me on the right painful path!


  • I survived the hour long Uno hand

    @PleegWat said:

    I disagree. From my JS console:

    0 == "0" == false
    false

    Classic error.

    (0 == "0")
    true
    0 == false
    true
    "0" == false
    true
    0 == "0" == false
    false
    (0 == "0") && ("0" == false)
    true


  • Totally forgot about LOGO, I guess that was my first language.



  • Go:

    package main
    
    func main() {
        // put code here
    }
    

    or Python/Ruby:

    # put code here
    

    or BrainFuck:

    put code here
    

  • BINNED

    @ben_lubar said:

    or BrainFuck:

    +[------->++<]>++.+++++.-.[---->+<]>+++.+[->+++<]>.++++++++++++.-----------.+.--[--->+<]>-.-[--->++<]>--.---.+++++++++++++.-------------.
    ```</blockquote>
    
    FTFY

  • SockDev

    is there a REPLIT for brainfuck yet? or maybe a fiddler?


  • BINNED

    @accalia said:

    is there a REPLIT for brainfuck yet? or maybe a fiddler?

    Sounds like a fun project if not. Need to get myself a domain for such tomfoolery though,


  • SockDev

    well if you don't mind the EVE reference i happen to be sitting on CaldariCoder.com ;-)


  • BINNED

    @accalia said:

    well if you don't mind the EVE reference i happen to be sitting on CaldariCoder.com

    CALDARI FOR LIFE, BABY!

    Well, used to be, no time for EVE these days. Also, I heard they nerfed my beloved Drakes to hell :'(

    Yes, Drakes, shut up! I rocked that thing like nobody's business!


  • SockDev

    wouldn't know a blessed thing about it. never played the game. I just sniped the domain from a friend of mine (i was going to sell at cost, just wanted to have a good laugh) but they decided to go with a different domain in the end.


  • BINNED

    @accalia said:

    wouldn't know a blessed thing about it.

    Don't worry, someone is sure to come along and berate me for my choice of favourite ship anyway :stuck_out_tongue:


  • SockDev

    all i want to know about that game is:

    is "Ramming Speed" followed by "All hands, brace for impact!" a valid set of instructions with real gameplay effects?

    because my favorite space based combat games always have at least one kamikaze based fight.

    i love killing my enemies star bases and dreadnoughts with mosquitos.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.